Android SDK - Media Player Video from URL

后端 未结 3 553
忘掉有多难
忘掉有多难 2020-12-15 08:19

I\'ve tried to find a simple tutorial which explains how to load a video from a URL into the android media player but unfortunately I couldn\'t find any!

I have trie

相关标签:
3条回答
  • 2020-12-15 08:53

    I think you can find useful thinks Here.. about playing video from different sources.

    If your using Emulator , First, do not use the emulator for testing video playback. Its ability to handle video playback is very limited. Use an actual Android device.

    Second, always check LogCat (adb logcat, DDMS, or DDMS perspective in Eclipse) for warnings when you run into multimedia problems. OpenCORE -- the multimedia engine used by Android -- has a tendency to log error-level conditions as warnings.

    For example, your video file may not be set up for progressive download, which is required for HTTP streaming. On Linux, you can patch up MP4 videos for progressive download by installing MP4Box and running MP4Box -hint .

    Hope this explanation works for you..

    0 讨论(0)
  • 2020-12-15 08:55

    You can use a VideoView. Here is an example:

    VideoView videoView = (VideoView) findViewById(R.id.videoView);
    //Use a media controller so that you can scroll the video contents
    //and also to pause, start the video.
    MediaController mediaController = new MediaController(this); 
    mediaController.setAnchorView(videoView);
    videoView.setMediaController(mediaController);
    videoView.setVideoURI(Uri.parse(videoUrl));
    videoView.start();
    

    EDIT

    You should provide the URI (having a String url variable, where it has the url of the video) with this code Uri.parse(url). And also be sure if the url is appropriate. Also, have you provided the appropriate permissions to your app, as AkashG suggested, (since it uses the internet you will need to add <uses-permission android:name="android.permission.INTERNET" > in your app's Manifest.xml)? Finally you should define your activity MediaPlayerActivity in in your app's Manifest.xml

    End of EDIT

    You can also use MediaPlayer. The Android developers site has a good tutorial here.

    0 讨论(0)
  • 2020-12-15 09:11

    you can load video from url as:

    VideoView videoView = (VideoView) findViewById(R.id.view);
    MediaController controller = new MediaController(this);
    videoView.setVideoPath("url of the video");
    videoView.setMediaController(controller);
    videoView.start();
    

    Add internet permission in manifest file.

    0 讨论(0)
提交回复
热议问题