gpt4 book ai didi

java - Android - 媒体播放器错误 : attachnewplayer called in state 64

转载 作者:太空狗 更新时间:2023-10-29 13:49:30 24 4
gpt4 key购买 nike

我正在按照下面的帖子创建简单的音乐播放器,但是从列表中选择任何歌曲或从 MediaController 中按上一个/下一个都会出现以下错误。我正在使用奥利奥(Andoid 8.1.0 API 27)。

public void playSong()
{
Song playSong = songs.get(songPosn);
songTitle=playSong.getTitle();
long currSong = playSong.getID();
Uri trackUri = ContentUris.withAppendedId(android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,currSong);
try
{
player.setDataSource(getApplicationContext(), trackUri);
player.prepareAsync();
}
catch(Exception e){
Log.e("MUSIC SERVICE", "Error setting data source", e);
}

错误 MediaPlayer 错误:在状态 64 中调用了 attachnewplayer

引用:Create Simple Music Player

最佳答案

您必须重置播放器,还必须设置 setAudioStreamType,因此您的代码如下所示

try 
{
player.reset();
player.setDataSource(getApplicationContext(), trackUri);
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
player.prepareAsync();
}

关于java - Android - 媒体播放器错误 : attachnewplayer called in state 64,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49905288/

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