Dynamic Http Streaming in Android to play live Flash video - android

I am trying to connect my android application with FTP Server which is broadcasting multiple streams using Dynamic Http Streaming at different bit rates.Flash Messaging Server(FMS) is using H.264 codec to broadcast video in flv format.On client side(Android) I am getting f4m(manifest (xml) file)) having diffrent streams.
I am unable to use the f4m file to fetch video in android from FMS.
String url = "http://d2233avv69kunu.cloudfront.net/hds-live/livepkgr/_definst_/liveevent/livestream.f4m";
Uri uri = Uri.parse(url);
// videoView.setVideoURI(uri);
videoView.setVideoPath(str);
MediaController mc = new MediaController(this);
//VMRuntime.getRuntime().setMinimumHeapSize(40);
mc.setAnchorView(videoView);
videoView.setMediaController(mc);
System.out.println("Max Memory - "+java.lang.Runtime.getRuntime().maxMemory());
videoView.requestFocus();
videoView.setOnPreparedListener(new OnPreparedListener()
{
public void onPrepared(MediaPlayer mp)
{
videoView.start();
}
});
In above code I am trying to run video in Video View component by passing link of f4m file.
Flash encoder convert video into 3 file formats as listed below
.f4m (manifest files) - Bootstrap Info,Metadata, Bitrate, Flash Access license Server location
.f4f (fragment files) - extends the F4V format,MP4 fragment std
.f4x (index files) - binary
Kindly provide solution to play video on different android devices via Http Streaming in android.
Thanks in advance.

1) You have left something out of your code. What is str that you are passing to setVideoPath? (this is somewhat irrelevant, though...)
2) The MediaPlayer (and thereby VideoView) cannot play Flash video at all. It's simply not supported. It definitely won't understand an XML file, either, so passing it the f4m file is pointless.

Related

How to decode and play the .h264 video from amazon s3 server in android?

I have .h264 videos in server, how to decode that video and playing in android?
I am using the FFMPEG to play those videos but in FFMPEG sample it takes
the video from SD-card and successfully play's the video. I am using the
surface view to play those videos. My question is how to play .h264 video from amazon s3 server in android?
Thanks in advance.
Make your videos(files) in the s3 bucket public,
and use that public url, it will be accessible everywhere.
EDIT
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();
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 provide the appropriate permissions to your app (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
You can also use MediaPlayer. The Android developers site has a good tutorial here.
H.264
According to this, Android supports h.264 Baseline Profile playback. So your h.264 video is not Baseline Profile or possibly it contains an unsupported audio.
You should note that there are many h.64 flavors, so you should check your video file: http://www.niallkennedy.com/blog/2010/07/h264-video.html
You need make sure your H.264 video is in the codec that your Android device can accept, otherwise, you need re-encode it.
I have Complete solve my issue by this code May be It will Help you.
layout.xml
<VideoView
android:id="#+id/videoview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
.class
String FileUrl="decoded url";
MediaController mediacontroller = new MediaController(this);
mediacontroller.setAnchorView(videoView);
Uri video = Uri.parse(FileUrl);
videoView.setMediaController(mediacontroller);
videoView.setVideoURI(video);
manifesto.xml
permitions
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

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

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.

Android Video streaming from HttpResponse object

I want to play video content from HttpResponse object. The content is downloading from a streaming sever.
My requirement is to create a HTTP POST request to the server. Request contains the URL of video, username and password of the user for authentication purpose.
I wish to know how can we create a HTTP POST request and play/download the video.
Kindly provide some hints, steps/code to proceed.
Thanks,
I am not 100% sure, but I think that you can't stream most of the video due to the way the format stores the meta data of the video. That's why you tube has to convert your video files instead of just showing them in any format.
There are protocols that encapsulate this metadata and allows you to stream any video (that's what youtube mobile does). You should take a look at RTSP: http://en.wikipedia.org/wiki/Real_Time_Streaming_Protocol
If you use an rtsp link in a videoView it should stream the video flawlessly. The point is that your problem is server and not client related.
As an exercise you could grab an rtsp link from m.youtube.com and just pass to a videoView using setVideoPath and it should work.
If can't change the server implementation then you probably them I guess your solutions are:
1) Download and decode the video yourself, you would have to handle all the metadata and ensure that the video does work though. You could, theoretically, compile ffmpeg for android to help you with that, but I couldn't compile it to android with the network option on. That is a lot of work.
2) Write your own implementation of RTSP or other streaming protocol. Download the video in a thread and them create a local server in the device to stream that video file to a videoView instance. I actually have this working on an app. Android doesn't support the specific protocol that the client's servers use and I had to get it working. It took me a full month to do this. I can't post any example code because it's all the client's, but I could give you some further info on this if you are interested.
Either way, if you can't change the server/format of the video then you should prepare for a whole lot of work.
check the below code for showing a url http or rtsp in Video View.
Now before invoking your videoview .. just get
public class VideoViewDemo extends Activity {
/**
* TODO: Set the path variable to a streaming video URL or a local media
* file path.
*/
private String path = "";
private VideoView mVideoView;
#Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.videoview);
mVideoView = (VideoView) findViewById(R.id.surface_view);
if (path == "") {
// Tell the user to provide a media file URL/path.
Toast.makeText(
VideoViewDemo.this,
"Please edit VideoViewDemo Activity, and set path"
+ " variable to your media file URL/path",
Toast.LENGTH_LONG).show();
} else {
/*
* Alternatively,for streaming media you can use
* mVideoView.setVideoURI(Uri.parse(URLstring));
*/
mVideoView.setVideoPath(path);
mVideoView.setMediaController(new MediaController(this));
mVideoView.requestFocus();
}
}
}
Now since your requirements are different first make http post request to your server ... get the desired input stream.. write that stream as mp4 to your local file system. then you can use below code to play content
// this can be path on file system
String path="/adf.mp4" ;
public void playVideo() {
MediaController mediaController = new MediaController(this);
mediaController.setMediaPlayer(videoView);
videoView.setVideoPath(path);
videoView.setMediaController(mediaController);
videoView.requestFocus();
videoView.start();
mediaController.show();
I tried this and it worked for me :D no rtsp no nothing, just a url with a mp4 video and it played!
public class VideoActivity extends Activity {
public static final String KEY = "video_id";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fotogaleria_video);
Intent i = getIntent();
if(i.hasExtra(KEY)){
String url = "https://sites.google.com/site/tempmp4download/bnm.mp4";
VideoView vv = (VideoView)findViewById(R.id.fotogaleria_video);
// vv.setVideoPath(url);
vv.setVideoURI(Uri.parse(url));
vv.setMediaController(new MediaController(this));
vv.requestFocus();
vv.start();
}
}
}
Look into following links
http://www.softwarepassion.com/android-series-get-post-and-multipart-post-requests/
http://w3mentor.com/learn/java/android-development/android-http-services/performa-a-http-post-request-with-the-httpclient-in-android/
For streaming, I think you have to download the full file, and then show it in the video player.

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