gpt4 book ai didi

java - 启动/停止媒体播放器 android studio

转载 作者:行者123 更新时间:2023-12-02 09:00:51 24 4
gpt4 key购买 nike

播放/停止按钮 - 如何让音乐从头开始播放?停止功能不是暂停功能``

    audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);

b_play = (Button) findViewById(R.id.b_play);
b_play.setEnabled(false);
b_play.setText("Loading");


mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);

new PlayerTask().execute(stream);

b_play.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view ) {
if (started) {
started = false;
mediaPlayer.pause();
b_play.setText("PLAY");
} else {
started = true;
mediaPlayer.start();
b_play.setText("STOP");
}
}
});

感谢您的帮助

最佳答案

调用mediaPlayer.seekTo(0)之后mediaPlayer.pause();

b_play.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view ) {
if (started) {
started = false;
mediaPlayer.pause();
mediaPlayer.seekTo(0);
b_play.setText("PLAY");
} else {
started = true;
mediaPlayer.start();
b_play.setText("STOP");
}
}
});

关于java - 启动/停止媒体播放器 android studio,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60171952/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com