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 tried several things to try get it working but still no luck.
What is the best way to have a MediaPlayerActivity just load a video from a URL?
Thanks
EDIT:
I have 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 go to this activity.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With