我有這樣的方法打一個按鈕的音頻文件:安卓:暫停流音頻上的MediaPlayer
final MediaPlayer mediaplayer = MediaPlayer.create(
this,
Uri.parse("android.resource://" + getPackageName() + "/"
+ R.raw.inro));
mediaplayer.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
if (mediaplayer.isPlaying()) {
mediaplayer.pause();
} else {
mediaplayer.start();
}
}
});
我想要做的是,當音頻播放和用戶點擊該按鈕再一次,音頻會暫停,但是當他再次點擊時,音頻將恢復。
任何人都可以幫助我嗎?謝謝
更新:
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_nav_back:
WWHApplication.getMapActivityIntance().getVideoLocationDB();
WWHApplication.getMapActivityIntance().initLocations();
if (category == 'f') {
if (WWHApplication.getFavoritesListActivityIntance() != null)
WWHApplication.getFavoritesListActivityIntance()
.loadListView();
}
finish();
break;
case R.id.btn_tool_audio:
final MediaPlayer mediaplayer = MediaPlayer.create(this,
Uri.parse("android.resource://" + getPackageName() + "/"
+ R.raw.inro));
if (mediaplayer.isPlaying()) {
mediaplayer.pause();
} else {
mediaplayer.start();
}
break;
您現在面臨的問題是什麼? –
暫停方法不起作用,當用戶在播放音頻時單擊按鈕時,它什麼也不做 – hectichavana