Android VideoView Playback Controls Show "Play" Initially Instead of "Pause" Even Though File is Already Playing
Asked Answered
L

2

6

Good afternoon/morning! Hoping someone could help me out with a small problem I'm having. I'm playing a remote .mp3 file using a VideoView and a custom MediaController.

My MediaController looks like this:

public class MyMediaController extends MediaController {

public MyMediaController(Context context) {
    super(context);      
}

// Do nothing on the overridden hide method so the playback controls will never go away.
@Override
public void hide() {

}

// Override the dispatchKeyEvent function to capture the back KeyEvent and tell the activity to finish.
@Override
public boolean dispatchKeyEvent(KeyEvent event)
{
    if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) 
    {
        ((Activity) getContext()).finish();
    }

    return super.dispatchKeyEvent(event);
}

}

And my code to attach it to my VideoView looks like this:

    VideoView videoView = (VideoView) findViewById(R.id.VideoView);

    // Use our own media controller, which inherits from the standard one. Do this to keep 
    // playback controls from disappearing.
    mediaController = new MyMediaController(this);
    mediaController.setAnchorView(videoView);

    Uri video = Uri.parse(URL);

    videoView.setMediaController(mediaController);
    videoView.setVideoURI(video);

    // Set a handler that will show the playback controls as soon as audio starts.
    videoView.setOnPreparedListener(new OnPreparedListener() {

        @Override
        public void onPrepared(MediaPlayer arg0) {

            mediaController.show();
        }

    });

    videoView.start();

The problem I'm having is that when the .mp3 file starts playing, the control bar at the bottom has the "Play" button showing (i.e. triangle) instead of the "Pause" button (two parallel bars) even though the audio is already playing. Anyone know how to fix this?

EDIT 1:

I'd also be interested in any other solutions for playing a remote .mp3. The only requirements I have are that the user can pause/play the audio and also see what the name of the audio file (title) is.

Thank you!

Late answered 23/3, 2013 at 2:48 Comment(1)
Have Solved this IssueIranian
I
4

Try This : It solved the Issue For Me.

mMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
    @Override
    public void onPrepared(MediaPlayer mp) {
        mp.start();
        mMediaController.show();
    }
});
Iranian answered 13/4, 2015 at 5:22 Comment(0)
D
0

Simply:

@Override
        public void onPrepared(MediaPlayer arg0) {

         if (mediaController.isShowing==false) {mediaController.show();}
        }
Delanty answered 17/7, 2014 at 13:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.