6

下午好/早上好!希望有人可以帮助我解决我遇到的一个小问题。我正在使用 aVideoView和 custom播放远程 .mp3 文件MediaController

我的 MediaController 看起来像这样:

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);
}

}

我将其附加到我的VideoView外观的代码如下所示:

    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();

我遇到的问题是,当 .mp3 文件开始播放时,底部的控制栏显示“播放”按钮(即三角形)而不是“暂停”按钮(两个平行条),即使音频是已经在玩了。有人知道怎么修这个东西吗?

编辑1:

我也对播放远程 .mp3 的任何其他解决方案感兴趣。我唯一的要求是用户可以暂停/播放音频,还可以查看音频文件(标题)的名称。

谢谢!

4

2 回答 2

4

试试这个:它为我解决了这个问题。

mMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
    @Override
    public void onPrepared(MediaPlayer mp) {
        mp.start();
        mMediaController.show();
    }
});
于 2015-04-13T05:22:10.087 回答
0

简单地:

@Override
        public void onPrepared(MediaPlayer arg0) {

         if (mediaController.isShowing==false) {mediaController.show();}
        }
于 2014-07-17T13:16:34.343 回答