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
Related
I am facing the issue in playing the same audio after completing the audio. In my case i am using the play and pause function in a single button. When mediaplayer is playing the pause icon is visible ,when the audio is paused the play icon is visible.My problem is after audio is finished palying the audio, the mediaplayer seekbar should be in starting point of the audio and play button should be visible. How can i do this.
I tried mediaPlayer.setLooping(true); but the after completing the audio it starts again but pause icon is visible and audio is playing continiously.
also i tried `
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer mediaPlayer) {
// mediaPlayer.seekTo((int) startTime);
stop.setVisibility(View.GONE);
play.setVisibility(View.VISIBLE);
seekBar.setProgress((int) startTime);
}
});
In this method it shows only the mediaplayer completing state.
My Requirement is after completing the audio the mediaplayer should be in initial state and in pause condition. If audio is pause means the play icon should be visible.
In above image while playing the audio the pause image is visible, while in pause condition the play icon will be visible. When the audio is completed the seekbar position should be in starting point and audio should be pause condition.How to do this please help me.
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer mediaPlayer) {
// mediaPlayer.seekTo((int) startTime);
// stop.setVisibility(View.GONE);
// play.setVisibility(View.VISIBLE);
// seekBar.setProgress((int) startTime);
seekBar.setProgress(0);
if (mediaPlayer.isPlaying()){
stop.setVisibility(View.VISIBLE);
play.setVisibility(View.GONE);
}else {
stop.setVisibility(View.GONE);
play.setVisibility(View.VISIBLE);
}
}
});
I hope it's helpful to you ..!
I am working on a application in which i have to play a horn sound and i am having a sound clip of it. Now i want to play this sound file in a loop but i am getting a second lag once its repeat the same file. I am using media player class to play the sound.
Please let me know how i can remove this lag to play a sound file without a lag.
final MediaPlayer mp_horn1 = MediaPlayer.create(this, R.raw.horn_wf);
mp_start.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
mp_start.start();
}
});
Hey use this code for play sound in loop.
final MediaPlayer mp_horn1 = MediaPlayer.create(this, R.raw.horn_wf);
mp_start.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
mp_horn1..setLooping(true);
mp_start.start();
}
});
You have to use this - .setLooping(true);
Hope this will work. All the best.
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.
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();
}
}
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);
}
});