Android SDK - Media Player Video from URL

I tried to find a simple tutorial that explains how to load a video from a URL into an Android media player, but unfortunately I could not find it!

I tried a few things to try to get it to work, but still no luck.

What is the best way to have MediaPlayerActivity, just download the video from the url?

thanks

EDIT:

I tried the following code as suggested:

VideoView videoView = (VideoView) findViewById(R.id.your_video_view); MediaController mediaController = new MediaController(this); mediaController.setAnchorView(videoView); videoView.setMediaController(mediaController); videoView.setVideoURI(Uri.parse("url-here")); videoView.start(); 

It just crashes when I move on to this operation.

+8
android android-mediaplayer android-video-player
source share
3 answers

You can use 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 must provide a URI (with the String url variable where it has the video URL) using this Uri.parse(url) code. Also make sure the url is appropriate. Also, did you provide the appropriate permissions for your application, as suggested by AkashG (since it uses the Internet, you need to add <uses-permission android:name="android.permission.INTERNET" > to your Manifest.xml application)? Finally, you must define your MediaPlayerActivity activity in your Manifest.xml application.

End of EDIT

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

+15
source share

you can download 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 permission to access the Internet in the manifest file.

+5
source share

I think you can find useful thinks here .. about playing videos from different sources.

If you are using an emulator, First, do not use an emulator to test video playback. Its ability to handle video playback is very limited. Use a real Android device.

Secondly, always check LogCat (adb logcat, DDMS or DDMS perspective in Eclipse) for warnings when launching multimedia tasks. OpenCORE, the multimedia engine used by Android, tends to record error level conditions as warnings.

For example, your video file cannot be configured for the progressive download required for streaming HTTP. On Linux, you can update MP4 video for progressive download by installing MP4Box and running MP4Box -int.

Hope this explanation works for you.

0
source share

All Articles