gpt4 book ai didi

Android >=5.0 MediaPlayer 准备失败

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

我在 Android SDK >= 21 设备上播放流媒体(mp4/mp3 中的视频和音频)时遇到 MediaPlayer 问题。正如预期的那样,旧设备一切正常。我搜索了一些主题,发现它可能是 NuPlayer 的情况,它是 AwesomePlayer 的实验性替代品,但这并没有解决我的问题,即使在将它改回 AP 之后也是如此。

我被卡住了,所以我很感激任何帮助。

我的代码:


new AsyncTask() {

@Override
protected Void doInBackground(String... paths) {
if (mPlayer == null) {
mPlayer = new MediaPlayer();
} else {
mPlayer.reset();
}

if (mPlayer != null && mPlayer.isPlaying()) {
mPlayer.start();
}
String source = paths[0];


try {

mPlayer.setDataSource(source);
mPlayer.prepare();

mPlayer.start();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}

我的堆栈跟踪如下:


03-23 16:19:19.582: D/MediaPlayer(8241): Couldn\'t open file on client side, trying server side
03-23 16:19:53.902: E/MediaPlayer(8241): error (1, -2147483648)
03-23 16:19:53.905: D/MediaPlayer(8241): create failed:
03-23 16:19:53.905: D/MediaPlayer(8241): java.io.IOException: Prepare failed.: status=0x1
03-23 16:19:53.905: D/MediaPlayer(8241): at android.media.MediaPlayer._prepare(Native Method)
03-23 16:19:53.905: D/MediaPlayer(8241): at android.media.MediaPlayer.prepare(MediaPlayer.java:1125)
03-23 16:19:53.905: D/MediaPlayer(8241): at android.media.MediaPlayer.create(MediaPlayer.java:866)
03-23 16:19:53.905: D/MediaPlayer(8241): at android.media.MediaPlayer.create(MediaPlayer.java:839)
03-23 16:19:53.905: D/MediaPlayer(8241): at android.media.MediaPlayer.create(MediaPlayer.java:818)
03-23 16:19:53.905: D/MediaPlayer(8241): at myapp.FrameVideo$6.doInBackground(FrameVideo.java:609)
03-23 16:19:53.905: D/MediaPlayer(8241): at myapp.FrameVideo$6.doInBackground(FrameVideo.java:1)
03-23 16:19:53.905: D/MediaPlayer(8241): at android.os.AsyncTask$2.call(AsyncTask.java:288)
03-23 16:19:53.905: D/MediaPlayer(8241): at java.util.concurrent.FutureTask.run(FutureTask.java:237)
03-23 16:19:53.905: D/MediaPlayer(8241): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
03-23 16:19:53.905: D/MediaPlayer(8241): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
03-23 16:19:53.905: D/MediaPlayer(8241): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
03-23 16:19:53.905: D/MediaPlayer(8241): at java.lang.Thread.run(Thread.java:818)

最佳答案

这是我的代码及其工作请试试这个

AssetFileDescriptor afd;
// new music player object for new page
mediaPlayerSound = new MediaPlayer();

try {
afd = getAssets().openFd("Audio/" + soundSource);
mediaPlayerSound.setDataSource(afd.getFileDescriptor(),
afd.getStartOffset(), afd.getLength());

mediaPlayerSound.prepare();
mediaPlayerSound.start();

mediaPlayerSound
.setOnCompletionListener(new OnCompletionListener() {

@Override
public void onCompletion(MediaPlayer mp) {
// TODO Auto-generated method stub
}
});

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

关于Android >=5.0 MediaPlayer 准备失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29214265/

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