I am trying to play two video views using the same media controller but it seems impossible to play them and stop them and seek through both at the same time
can someone suggest a solution here is what I am trying :
//2 video views
videoview=(VideoView)findviewbyid(R.id.videowview);
videoviewtwo=(VideoView)findviewbyid(R.id.videowview2);
//the media controller
MediaController mc =new MediaController(this);
//setting uri for both:
videoview.setVideoURI(uri);
videoviewtwo.setVideoURI(uri1);
//setting same media controller object for both
videoview.setMediaController(mc);
videoviewtwo.setMediaController(mc);
//finally start both
videoview.Start();
videoviewtwo.Start();
after this both play well at the first time but when I try to repeat only one starts the other doesnt, thank you for your help.
Edit: I want them both to play at the same time each time I repeat the process .
You need to release and set the mediaplayer to null before you can start the new video. Try to call this when the video has stopped and before you start a new video so you know that the mediaplayer is not busy.
private void releaseMediaPlayer() {
mMediaPlayer.release();
mMediaPlayer = null;
}
So next is to find out when the mediaplayer have stopped playing your video. A hint: MediaPlayer.OnCompletionListener
Related
I am trying to load the following free online camera in my app (site: http://www.earthcam.com)
for example, this video.
and I found the video address by IDM (http://video3.earthcam.com/fecnetwork/5187.flv/chunklist_w664887517.m3u8)
I loaded the video in my app with the following code:
String VideoURL = "http://video3.earthcam.com/fecnetwork/5187.flv/chunklist_w664887517.m3u8";
MediaController mediacontroller = new MediaController(MainActivity.this);
mediacontroller.setAnchorView(videoview);
// Get the URL from String VideoURL
Uri video = Uri.parse(VideoURL);
videoview.setMediaController(mediacontroller);
videoview.setVideoURI(video);
videoview.requestFocus();
videoview.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
// Close the progress bar and play the video
public void onPrepared(MediaPlayer mp) {
videoview.start();
}
});
Now I have two problems
How can I play the video in my app with the original url(for example www.earthcam.com/usa/illinois/chicago/field/?cam=fieldmuseum)
How can I display all tools (zoom in, zoom out, volume, stop, pause, like, view, map, etc.)
First question why the video is not playing: the support of a livestream in MediaController is limited. I would suggest you to ExoPlayer https://github.com/google/ExoPlayer
It should handle a livestream playback.
Second question: in order to display all tools that you mentioned you would need an access to the control of the camera either via API or via URL parameters. Then you would need to add this buttons as an overlay on top of the video player and connect buttons to the API calls. However, I don't think that EarthCam provides public API for a camera control.
I'm using VideoPlayer in my app. It play everything fine but when I want to scroll on the media player's bar, usually it gives me the error : Sorry, this video cannot be played. and I have to restart the video to watch it again. All I found is if I stop the video and scroll the bar it will be fine. I just wonder how can I fix this problem ? how can I access to media player's bar. Hens I can pause the video onClick. My code:
MediaController mediaController = new MediaController(
rootView.getContext());
mediaController.setAnchorView(video);
Uri uri = Uri.parse(passVideo.file_link);
video.setMediaController(mediaController);
video.setVideoURI(uri);
video.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer arg0) {
mProgress.setVisibility(View.INVISIBLE);
video.requestFocus();
video.start();
}
});
Many people get this error like you,
Bugs :
Sorry this video is not valid for streaming to this device.
Sorry, this video can not be played.
You can find out at Sorry, this video is not valid for streaming to this device in Http streaming android
Thanks,
Alright so i'm trying to create a mediacontroller to control my audio file that plays whenever i click on an imageview.
i tried this but it wouldn't recognized the audio file (mysound)
MediaController mc = new MediaController(this);
mc.setMediaPlayer(mysound);
mysound.setMediaController(mc);
You should be able to call start per the Android documentation once you have provided a valid audio file.
MediaPlayer mediaPlayer = MediaPlayer.create(context, R.raw.sound_file_1);
mediaPlayer.start(); // no need to call prepare(); create() does that for you
I set in MediaPlayer source as url with remote mp3 file. I want listen, where start playing song.
At start some time need to download mp3 header (caching) and only after start playing song. How I can know about this moment? I know only simple way: check at timer isPlaying status...
If you use Android native MediaPlayer, there's an event called onPrepare which is called when the mediaplayer is ready to play your music
For example how to catch the above event on VideoView.
video = new VideoView(activity);
video.setOnPreparedListener(new OnPreparedListener() {
}
I have ONE object MediaPlayer mediaplayer. I use it to play different sounds, one after another.
mediaplayer = MediaPlayer.create(context, ResIdMusicONE);
mediaplayer.start();
// some user input
mediaplayer.release();
mediaplayer = null;
// some other user input
mediaplayer = MediaPlayer.create(context, ResIdMusicTWO);
mediaplayer.start();
// some user input
mediaplayer.release();
mediaplayer = null;
Sometimes is works fine. But sometimes the two sounds are played at the same time. And at positions, where mediaplayer should already have been released and be equal null.
Thanks for the help.
If I were you I would use the SoundPool class for this. With SoundPool you can set the number of streams to play at the same time, so by setting that to 1 you can just call play() over and over and the most recent call to play() will be the only sound that you hear.
Take a look at my post a while back. It has an example of the SoundPool class in the question.
Edit:
Have you tried creating a new instance and calling the prepare() every time you want to start a new sound?
mediaplayer = new MediaPlayer();
mediaplayer.setDataSource(path);
mediaplayer.prepare();
mediaplayer.start();
Though actually now that I think about it, I'm pretty sure you only need to do that if you are using a file from the sdcard not from your resources... Hmmm.