Android VideoView playback controls show “play” first instead of “pause”, although the file is already playing

Good afternoon / morning! Hoping someone can help me with the little problem I am having. I play a remote .mp3 file using VideoView and a custom MediaController .

My MediaController is as follows:

 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 is as follows:

  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 am facing is that when the .mp3 file starts playing, the control panel at the bottom has a “Play” button that displays (ie a triangle) instead of the “Pause” button (two parallel bars), although the sound is already reproduced. Does anyone know how to fix this?

EDIT 1:

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

Thanks!

+6
source share
2 answers

Try this: he solved the problem for me.

 mMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { @Override public void onPrepared(MediaPlayer mp) { mp.start(); mMediaController.show(); } }); 
+3
source

Just:

 @Override public void onPrepared(MediaPlayer arg0) { if (mediaController.isShowing==false) {mediaController.show();} } 
0
source

All Articles