Android SDK - Media Player Video from URL
Asked Answered
A

3

14

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.

Ashley answered 10/7, 2012 at 10:54 Comment(0)
P
24

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.

Pothook answered 10/7, 2012 at 11:5 Comment(3)
I tried this and it crashes when i go to the media player activityAshley
This requires API LEVEL 21Mauceri
No sound can you help ?Clinic
D
7

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.

Diegodiehard answered 10/7, 2012 at 11:2 Comment(0)
H
0

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..

Hoary answered 10/7, 2012 at 11:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.