Android的VideoView播放控制展览会暨QUOT;播放"最初,代替"暂停"即使文件已在播放 [英] Android VideoView Playback Controls Show "Play" Initially Instead of "Pause" Even Though File is Already Playing

查看:157
本文介绍了Android的VideoView播放控制展览会暨QUOT;播放"最初,代替"暂停"即使文件已在播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下午好/上午好!希望有人能帮助我,我有一个小问题。我打使用 VideoView 远程MP3档案,并自定义的MediaController

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.

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

}

和我的code将其连接到我的 VideoView 是这样的:

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

我遇到的问题是,当.MP3文件开始播放,在底部的控制栏有播放按钮的表现(即三角形),而不是暂停按钮(二双杠),即使音频正在播放。任何人都知道如何解决这个问题?

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?

编辑1:

我也有兴趣在任何其他的解决方案,用于播放远程.MP3。唯一的要求我必须是用户可以暂停/播放音频,并看看有什么音频文件(名称)的名称。

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.

感谢您!

推荐答案

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

Try This : It solved the Issue For Me.

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

这篇关于Android的VideoView播放控制展览会暨QUOT;播放"最初,代替"暂停"即使文件已在播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆