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
Related
I have an issue with ExoMedia implementation. Here is the repository of this very good video player library based on ExoPlayer.
https://github.com/brianwernick/ExoMedia
It solved my issues with streaming videos on some Android devices.
My only problem is, I can't change / control default media controllers. Original code was:
private VideoView contentView;
contentView.setVideoURI(Uri.parse("http://127.0.0.1:54852/"));
MediaController mediaControllerView = new MediaController(this);
mediaControllerView.setAnchorView(contentView);
contentView.setMediaController(mediaControllerView);
It worked nice with nice default media controller.
It appeared that after changing it to VideoView to EMVideoView which uses ExoPlayer disabled setMediaController method.
private EMVideoView contentView;
contentView.setVideoURI(Uri.parse("http://127.0.0.1:54852/"));
MediaController mediaControllerView = new MediaController(this);
mediaControllerView.setAnchorView(contentView);
*contentView.setMediaController(mediaControllerView);* <-- no such method
EMVideoView doesn't have it implemented. I can only set to use default controls using
contentView.setDefaultControlsEnabled(true);
If I set to false, no controls are shown, and unable to control playing. I couldn't find the way, how to add MediaController to EMVideoView.
The main reason of changing it is controllers used in EMVideoView have fully transparent background, and it's not visible on some videos at all. The standard ones from VideoView have nice grey background, and the best would use them.
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.
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();
Basically I'm setting up a VideoView to play music(more functionality than MediaPlayer) while I display a .gif in a webview. I'm not sure if I need multiple threads or something, but whenever I try to run both at once it either crashes, or doesn't play the music. Is it true that since my "Content View" is set to the WebView that I can't access objects(like the videoview) on my main.xml?
Code:
setContentView(R.layout.main);
musicPlayer = (VideoView)findViewById(R.id.player);
//run gif
view = new GifWebView(this, "file:///android_res/raw/kk.gif");
setContentView(view);
//start player
musicPlayer.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" + musicList[0]));
musicCounter =0;
musicPlayer.setOnCompletionListener(TrackRepeater);
musicPlayer.requestFocus();
musicPlayer.start();
The player works if I don't change context to the WebView obviously, not sure what to do here. Cheers.
Please elaborate on your reasons to use a VideoView to play music.
more functionality than MediaPlayer
VideoView is essentially a wrapper for SurfaceView and MediaPlayer. The extra functionality in VideoView should be only the stuff related to playing the video on the screen, which you aren't using. What specific reasons do you have for using that over MediaPlayer?
But I think you are right that by changing the content of your activity you are breaking the VideoView. You need to figure out a way to do it without calling setContentView() multiple times. There are many possibilities here are a two:
Get a reference to the parent view of your main.xml layout and call .addView() on it to add the GifWebView instead of calling setContentView() with it.
Add the declaration of the GifWebView to your xml layout and get the reference to it the same way as you have the VideoView.
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.