In my android app, i want to stream video from URL. For that i am using VideoView control. But it displays starts playing video after loading whole video. I want to perform async video streaming for that. Is async streaming possible with VideoView ? I want to display ProgressBar until video is loaded. Please help me to solve this problem.
Thank you.
Here is my code :
video_view_ = (VideoView) findViewById(R.id.video_view);
video_view_.setVideoURI(Uri.parse(path));
video_view_.setMediaController(new MediaController(this));
video_view_.requestFocus();
video_view_.start();
Related
I use videoview to play some .gif but cant. when I use to play gif or mp4 I receive cant play video but when I try to use webview everything is ok.
VideoView i = (VideoView) findViewById(R.id.videoView1);
i.setVideoPath("file:///android_asset/ad.gif");
i.start();
The current easiest way to get gifs to work outside of WebView is to use the Glide library with ImageView.
ImageView imageView = (ImageView) findViewById(R.id.my_image_view);
GlideApp.with(context).load("gif_source").into(imageView);
Edit: Didn't realise you also asked about MP4 (early morning). Here's a post which gives some good info on it as it can be quite complicated (things like making sure the MP4 is encoded in a format Android supports).
I have a link in the form
http://something.com/some/play.php
When I simply put and go on the browser, the video gets played. It is a live video.
I want to make request to this URL and then run the video in android view.
How to achieve that?
With a VideoView, you should be able to do the following:
String path="http://something.com/some/play.php";
Uri uri=Uri.parse(path);
VideoView video=(VideoView)findViewById(R.id.VideoView01);
video.setVideoURI(uri);
video.start();
Check out the documentation regarding VideoView, and here's an example on how you can stream using VideoView.
I have an ip camera and I want to include the video stream in an Android activity. To do that I included a VideoLayout with id video and I added this code to the onCreate method in the Activity.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
videoView = (VideoView) findViewById(R.id.video);
Uri video = Uri.parse("rtsp://192.168.1.225/axis-media/media.amp");
videoView.setVideoURI(video);
videoView.start();
}
It works but there is an annoying delay of 10 seconds between the acquisition of the image from the camera and the displaying to the phone. I want the delay lesser than 2 seconds. I know the problem is related the fixed size of the buffer used for caching images during RTSP session. If I use vlc I can view the stream well by setting network-caching=0. Is there a way to do that in Android? The software destination is a ROOTED Android 4.0.3. Can I resolve by taking advantage of the root? I read that I can set the media.stagefright.cache-params of the build.prop file but I don't know if it is useful and how to set it..
Please help me! Thank you!
Somewhere in my Android app I would like to play a youtube video,
in my activity, in a small view.
I'm trying to do this using VideoView, but no luck so far..
I wrote a simple activity, here is my code so far:
public class MainView extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
VideoView videoView = (VideoView) findViewById(R.id.VideoView);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
/*working good but IT'S NOT youtube*/ //Uri video = Uri.parse("http://commonsware.com/misc/test2.3gp");
/*NOT WORKING*/ //Uri video = Uri.parse("http://www.youtube.com/watch?v=hLQl3WQQoQ0&ob=av2e");
/*NOT WORKING (RTSP)*/ //Uri video = U-ri.parse("http://m.youtube.com/watch?gl=IL&hl=en&client=mv-google&feature=grec_mobile&v=6WHRxXY67UA");
/*NOT WORKING (RTSP)*/Uri video = Uri.parse("http://m.youtube.com/watch?gl=IL&hl=en&client=mv-google&v=wWub_aXPCVg");
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.start();
}
}
is it possible?
is there any other SDK component that can do that?
any ideas?
Thanks,
Amitos80
Google are releasing android components for YouTube "in the coming months", so hopefully by the end of 2012.
What I am doing in the meantime is using a WebView with loadData(), and passing in an IFrame as stated on the YoUTube API page. The Iframe is quite limited (most parameters don't even work, like controls=0), so if you need more flexibility like controlling the view then use the JavaScript API and then embed the JavaScript in the HTMl you pass into loadData.
I tried the Media Controller and couldn't get it to work, even though YouTube use it in there own app.
The other thing to try which i didn't get around to. Is to use the google search apis. You can specify a YouTube video and it will give you the URL's to the thumbnails, videos etc. This way you can get to the raw files (www.youtube.com/...../..../myfile.3gp) rather than calling a webpage. These might then be loadable in the MediaController.
If you know what video you want to view, you could just create an Intent with the url in it and use that to launch the Youtube app. You can see this SO Post for more details.
you can simply use youtube rtsp link in videoview as:
String myurl="rtsp://v4.cache4.c.youtube.com/CjYLENy73wIaLQk_ezfHQ9mvqRMYDSANFEIJbXYtZ29vZ2xlSARSBXdhdGNoYN-__7O28NSPUAw=/0/0/0/video.3gp";
Uri video = Uri.parse(myurl);
mVideoView = new VideoView(this);
mVideoView.setVideoURI(video);
myMediaController = new MediaController(this);
it works simply for me.
Is there anyway I can add a ProgressDialog in VideoView in Android while the video is not showing up yet. Because all I see is black screen until the video plays. I have struggling for almost a week trying to find the solution, please help me I would really appreciate it a lot. Thanks in advance!
Here is the code I am using:
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.yourvideos.mp4");
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.start();
best way is to use async task... preExecute method use showing dialog... doInBackground for setting the videoUri then in onPostExecute cancel the dialog... but if u had need to stop the Loading dialog as video starts playing, implement onPreparedListener and Register for
the video view
if you dont to want use async task then show the dialog before u set the path to videoview. then cancel it on "OnPrepared" listeners "onPrepared()" method. remember u should register with videoview...
I didn't test this but you might add the dialog, and populate it with the percentage fetched by http://developer.android.com/reference/android/widget/MediaController.MediaPlayerControl.html#getBufferPercentage()
use something like a timer to update it every few ms