gpt4 book ai didi

安卓媒体播放器 : Start called in state 4 error(-38, 0)

转载 作者:IT老高 更新时间:2023-10-28 23:12:00 26 4
gpt4 key购买 nike

这是用于从其他类动态获取文件名(.mp3)的代码,因为我的 Assets 文件夹中有许多 mp3 文件:

playAudioButton.setOnClickListener(new OnClickListener() {


@Override
public void onClick(View v)
{
FileName audio=new FileName();
String audioName=audio.getAudioName(count).toString();
if(audioName=="NO Audio")
{

Toast.makeText(getApplicationContext(), "No Audio for this page", Toast.LENGTH_SHORT).show();

}
else
{

try {
afd=getAssets().openFd(audioName + ".mp3");
mp = new MediaPlayer();
mp.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(),afd.getLength());
mp.prepareAsync();
mp.start();

} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}




}
});


}

原木猫:

03-20 11:21:28.726: E/SpannableStringBuilder(4418): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-20 11:21:28.726: E/SpannableStringBuilder(4418): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-20 11:22:24.968: D/libEGL(4579): loaded /vendor/lib/egl/libEGL_POWERVR_SGX540_120.so
03-20 11:22:24.976: D/libEGL(4579): loaded /vendor/lib/egl/libGLESv1_CM_POWERVR_SGX540_120.so
03-20 11:22:24.984: D/libEGL(4579): loaded /vendor/lib/egl/libGLESv2_POWERVR_SGX540_120.so
03-20 11:22:25.070: D/OpenGLRenderer(4579): Enabling debug mode 0
03-20 11:22:38.773: E/MediaPlayer(4579): start called in state 4
03-20 11:22:38.773: E/MediaPlayer(4579): error (-38, 0)
03-20 11:22:38.773: E/MediaPlayer(4579): Error (-38,0)

注意事项:1.我检查过堆栈溢出的类似线程答案是使用prepareAsync()2.我用过prepareAsync()

提前致谢。

最佳答案

您也可以使用下面的 onPrepared() 方法调用 start 方法,以便在 MediaPlayer 准备好之后调用 start()

mp.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
// TODO Auto-generated method stub

mp.start();

}
});

关于安卓媒体播放器 : Start called in state 4 error(-38, 0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15516469/

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