android- how to play video in VideoView? - android

I want to play video in a VideoView. which one is correct?
video.setOnPreparedListener(new OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
video.start();
}
});
or simply:
video.start();

Both method is right to play video but setOnPreparedListener is useful when you want to show ProgressBar when media is loading for play from SDCARD,webserver or streaming urls.
and if video.start(); called without setOnPreparedListener some delay occur during loading file then only black screen appear to user until video start.

Related

How play video without stop other audio tracks?

When I playing video in my application, other audio stop playing. Because my video has no sound, so I don't want to stop other audio.
I have tried to mute my video by set volume to 0 but it doesn't help
setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
mp.setVolume(0f, 0f);
}
});
Any help or suggestion would be great appreciated

How to remove the first 3 seconds from a mp4 file on android?

I want to remove the first 3 seconds from a mp4 video file on android, how can I do it with Android API?
If you are using VideoView for showing the video, try using below code.
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener()
{
#Override
public void onPrepared(MediaPlayer mp)
{
videoView.seekTo(3000);
}
});

How to play preroll?

I want to play preroll ad (Just like you tube) before playing any video live streaming in my app. Right now i am able to play video using URL through streaming but not able to find any way to play preroll please some one help me to achieve this goal.
Just provide a ArrayList of videoUrls for your media player. Use the OnCompletionListener interface and play the next (none-preroll) video when the preroll has been completed. From what Ive understood you can't feed the Android media player a list of urls, you have to setDataSource for each video.
//Starting the mediaplayer
private void playVideo() {
mediaPlayer.setDataSource(videoUrlList.get(playlistPosition));
mediaPlayer.prepareAsync();
}
#Override
public void onCompletion(MediaPlayer mp) {
//Look if the list has more videos
if (playlistPosition < videoUrlList.size() - 1) {
playlistPosition++;
if(mediaPlayer != null)
mediaPlayer.reset();
playVideo();
}else{
//If no more videos, quit MoviePlayer Activity
finish();
}
}

Buffering videos with VideoView

I have an Activity that takes a url and plays the video with a VideoView. This works fine.
However, there is a buffer time before the video starts playing. Because of this, the VideoView is black. There is no spinner indicating a buffer loading.
Is there a parameter of the VideoView that will show a spinner? If not, is there some message that gets broadcast when the video starts playing? That way I can show my own spinner and hide it when the message is received.
I've found the answer. Add a ProgressBar over the top of the VideoView and do the following:
mPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
mSpinner.setVisibility(View.GONE);
}
});

VideoView not supporting video in Android

I am using VideoView to play video.
If the video is not supported by the phone (such as my phone supporting only 480p video, not 720p which is the video I'm trying to play), it shows the dialog
Sorry,This video cannot be played
I want to do something after I click the dialog's "OK" button.
Where can I add the code to do this?
My code as below:
vv = (VideoView)this.findViewById(R.id.screen_video);
Uri uri = Uri.parse(FlePath);
vv.setVideoURI(uri);
vv.start();
After your code paste this.If you get this error then oncmpletion listner will call.
vv.setOnCompletionListener(new OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer mp) {
//release your MediaPlayer Resource
//do whatever you want
}
});
Hope this help you :)

Categories

Resources