3

我使用 MediaController 播放我的音频。但是,我想从我的 MediaController 中删除后退和前进按钮。请帮我。(PS。代码很有用)我该如何编辑它。

public class Main extends Activity implements MediaPlayerControl {
    private static final String PLAY_AUDIO = "PLAY_AUDIO";  
    private MediaController mMediaController
    private MediaPlayer mMediaPlayer;
    private Handler mHandler = new Handler();

    static Context context;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        context = this;


        mMediaPlayer = new MediaPlayer();
        mMediaController = new MediaController(this);

        mMediaController.setMediaPlayer(Main.this);
        mMediaController.setAnchorView(findViewById(R.id.audioView));
        mMediaController.setPrevNextListeners(new View.OnClickListener() {
            public void onClick(View v) {
                //next button clicked
            }       
        }, new View.OnClickListener() {
            public void onClick(View v) {
                //previous button clicked
            }
        });

        try { 
            mMediaPlayer.setDataSource(
                this,
                Uri.parse("android.resource://com.app.audioplayer/raw/allforyou")
            );
            mMediaPlayer.prepare();         
        } catch (IOException e) {
            Log.e(PLAY_AUDIO, "Could not open file " + "  " + " for playback.", e);         
        }

        mMediaPlayer.setOnPreparedListener(new OnPreparedListener() {
            public void onPrepared(MediaPlayer mp) {
                mHandler.post(new Runnable() {
                    public void run() {
                        mMediaController.show(0);
                        mMediaPlayer.start();
                    }
                });
            } 
        });
    }

}
4

1 回答 1

4

最简单的解决方案...

MediaController mediaController = new MediaController(this, false);

礼貌:@Meow meo(在原始问题的评论中)

于 2015-04-14T18:06:32.647 回答