Play mp4 file from URL on android - android

I've been researching for some time now, and all the questions I can find point to mp4 'hinting' but I have no control over the videos.
I was about to give up when i discovered that MX video player on the android market can somehow play these mp4 urls I have. So at the moment I use an intent to launch the urls in mx player but I'd much rather display the video within my app.
Any ideas how mx player does this would be great,
Thanks

Check this. It will help you.
String LINK = "http://www.boisestatefootball.com/sites/default/files/videos/original/01%20-%20coach%20pete%20bio_4.mp4";
setContentView(R.layout.video);
VideoView videoView =(VideoView)findViewById(R.id.webView);
MediaController mc = new MediaController(this);
mc.setAnchorView(videoView);
mc.setMediaPlayer(videoView);
Uri video = Uri.parse(LINK);
videoView.setMediaController(mc);
videoView.setVideoURI(video);
videoView.requestFocus();
videoView.start();

Refer this link i had pasted the whole code for playing the mp4 videos in your app by creating a videoview and you might minor error you can manually remove that error.

You can do it using FullscreenVideoView class. Its a small library project. it's gradle is :
compile 'com.github.rtoshiro.fullscreenvideoview:fullscreenvideoview:1.1.0'
It's steps is here:
your VideoView xml is like this
<com.github.rtoshiro.view.video.FullscreenVideoLayout
android:id="#+id/videoview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
In your activity , initialize it using this way:
FullscreenVideoLayout videoLayout;
videoLayout = (FullscreenVideoLayout) findViewById(R.id.videoview);
videoLayout.setActivity(this);
Uri videoUri = Uri.parse("YOUR_VIDEO_URL");
try {
videoLayout.setVideoURI(videoUri);
} catch (IOException e) {
e.printStackTrace();
}
That's it. Happy coding :)
If want to know more then visit here

Related

How to display mp4 video in videoview from raw folder

I am trying to display a mp4 video from a raw folder. The video is supposed to play in a videoview automatically when the app is open. I want the video to begin as soon as the activity is launched (This is the launcher activity). I also want the video to loop and have no sound. My xml is below.
<VideoView
android:id="#+id/launcherVideo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/linearLayout" />
This is the code I have.
String fileName = "android.resource://"+ getPackageName()+"/raw/launchervideo";
VideoView mvideo = (VideoView) findViewById(R.id.launcherVideo);
mvideo.setVideoPath(Launcher);
MediaController controller = new MediaController(this);
mvideo.setMediaController(controller);
mvideo.requestFocus();
mvideo.start();
}
This code currently does not do anything but display a blank screen when I run the app and I don't know why. Can anyone help out?
I don't see you use this variable, and I don't see how you define Launcher variable.
String fileName = "android.resource://"+ getPackageName()+"/raw/launchervideo";
to open video file from raw folder you can do this way:
Uri uri = Uri.parse(fileName);
mvideo.setVideoURI(uri);
mvideo.start()
I hope it can help solve your problem
Thanks for the help guys, I figured it out.
VideoView videoView = (VideoView) findViewById(R.id.launcherVideo);
Uri src = Uri.parse("android.resource://com.package/raw/video_name");
videoView.setVideoURI(src);
//videoView.setMediaController(new MediaController(this));
videoView.start();
This worked for me.

Android SDK - Media Player Video from URL

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

Play video from an Url without webview

I have to play Dailymotion videos in an Android APP, but I must not do it in a WebView . VideoView class just accepts files streamed, and Dailymotion API has'nt got any resource for Android.
Does anyone know how to implement it?
Thanks!
String LINK = "Your_Link_Goes_Here";
setContentView(R.layout.mediaplayer);
VideoView videoView = (VideoView) findViewById(R.id.video);
MediaController mc = new MediaController(this);
mc.setAnchorView(videoView);
mc.setMediaPlayer(videoView);
Uri video = Uri.parse(LINK);
videoView.setMediaController(mc);
videoView.setVideoURI(video);
videoView.start();
Try out this code..
VideoView is the best and in video view you can play streaming url also you can play the local files which you have on device sdcard or embeeded with in your app..
Refer this LINK this a sample
LINK

Media player using YouTube?

I am developing a sample application using MediaPlayer.By using the raw resources folder,the video can be played.But I want to play through URL.How can I achieve this?
My code is:
VideoView videoView = (VideoView) findViewById(R.id.VideoView);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
// Set video link (mp4 format )
Uri video = Uri.parse("http://www.youtube.com/watch?v=T1Wgp3mLa_E");
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.start();
You need to get the correct streaming(rtsp) url rather than the link to the player page you are using. You can get this programmatically using the google data api
Once you have done that you would simply replace
"http://www.youtube.com/watch?v=T1Wgp3mLa_E"
with "rtsp://v8.cache1.c.youtube.com/CiILENy73wIaGQnxa4t5p6BVTxMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp"
in your existing code and it should work.
Note: The quality of video, when streaming to your own videoview, can be very poor compared to how it looks when played on the youtube site or player app.
You have to rtsp links from gdata api :gdata api with this: http://gdata.youtube.com/feeds/api/videos?&max-results=20&v=2&format=1&q="+ URLEncoder.encode(activity.criteria)
Element rsp = (Element)entry.getElementsByTagName("media:content").item(1);
String anotherurl=rsp.getAttribute("url");
In gdata api only we are getting this type of links : rtsp://v3.cache7.c.youtube.com/CiILENy73wIaGQlOCTh0GvUeYRMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp
These are playing in VideoView.
My answer link :RTSP Links
In order to get better quality videos, I checked what these guys did. It helped me very very much!
I'm posting the link so you can checkout their project and use their code.

Video Streaming and Android

Today for one of my app (Android 2.1), I wanted to stream a video from an URL.
As far as I explored Android SDK it's quite good and I loved almost every piece of it.
But now that it comes to video stream I am kind of lost.
For any information you need about Android SDK you have thousands of blogs telling you how to do it. When it comes to video streaming, it's different. Informations is that abundant.
Everyone did it it's way tricking here and there.
Is there any well-know procedure that allows one to stream a video?
Did google think of making it easier for its developers?
If you want to just have the OS play a video using the default player you would use an intent like this:
String videoUrl = "insert url to video here";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(videoUrl));
startActivity(i);
However if you want to create a view yourself and stream video to it, one approach is to create a videoview in your layout and use the mediaplayer to stream video to it. Here's the videoview in xml:
<VideoView android:id="#+id/your_video_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
/>
Then in onCreate in your activity you find the view and start the media player.
VideoView videoView = (VideoView)findViewById(R.id.your_video_view);
MediaController mc = new MediaController(this);
videoView.setMediaController(mc);
String str = "the url to your video";
Uri uri = Uri.parse(str);
videoView.setVideoURI(uri);
videoView.requestFocus();
videoView.start();
Check out the videoview listeners for being notified when the video is done playing or an error occurs (VideoView.setOnCompletionListener, VideoView.setOnErrorListener, etc).

Categories

Resources