媒体播放器错误 (-38,0) 和错误 (1,-1010) [英] Mediaplayer error (-38,0) and error (1,-1010)

查看:48
本文介绍了媒体播放器错误 (-38,0) 和错误 (1,-1010)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我试图让媒体播放器工作,但在第一次安装时音乐没有开始播放(我认为这是因为可视化工具需要权限).但每次之后它都玩得很好.

So i am trying to get a mediaplayer to work, but on first install the music doesnt start playing (i think it's because of permissions needed for the visualizer). But everytime afterwards it plays just fine.

代码:

    mPlayer = MediaPlayer.create(this, R.raw.bik);
    mPlayer.setLooping(true);
    mPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
        @Override
        public void onPrepared(MediaPlayer mp) {
            mp.start();
        }
    });

日志猫:

11-23 17:18:29.979 28329-28329/com.waro.blockevader E/MediaPlayer: Error (-38,0)
11-23 17:18:29.979 28329-28329/com.waro.blockevader E/MediaPlayer: Error (-38,0)
11-23 17:18:29.979 28329-28329/com.waro.blockevader E/MediaPlayer: Error (1,-1010)
11-23 17:18:29.979 28329-28329/com.waro.blockevader E/MediaPlayer: Error (-38,0)
11-23 17:18:29.979 28329-28329/com.waro.blockevader V/MediaPlayer[Native]: isPlaying: 0
11-23 17:18:29.979 28329-28329/com.waro.blockevader E/MediaPlayer: Error (-38,0)

文件格式为.mp4

感谢您的帮助.

我每次之后的意思;

每次我授予权限并重新启动应用程序后,音乐就开始正常播放并且没有出现错误.

Everytime after i gave permissions and RESTARTED the app, the music starts playing just fine and no errors are given.

权限:

<uses-permission android:name="android.permission.RECORD_AUDIO"/>

推荐答案

我通过更改 onResumse() 中的一部分来修复它,

I fixed it by changing a part in the onResumse(),

不出所料,确实是权限造成了破坏,我有:

As expected it was indeed the permission causing havoc, i had:

if (ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED) {
        if (!mPlayer.isPlaying() && !mpCreated) {
            initTunnelPlayerWorkaround();
            init();
        } else {
            mPlayer.start();
            mVisualizerView.link(mPlayer);
        }
    } else {
        cleanUp();
        mPlayer.start();
        Log.i("boop","biep");
    }

最后通过那个日志发现它进入了else,这意味着它正在调用cleanUp();方法

And finally discovered by that log it was going into the else, meaning it was calling the cleanUp(); method

在我有的 cleanUp() 方法中:

And in the cleanUp() method i had:

private void cleanUp() {
    if (mPlayer != null) {
        mVisualizerView.release();
        if(!mPlayer.isPlaying()) {
            mPlayer.pause();
        }
    }
}

第二个 if 造成了严重破坏(废话),我通过将其更改为:

The 2nd if was causing havoc (duh) and i fixed it by changing it to:

private void cleanUp() {
    if (mPlayer != null) {
        mVisualizerView.release();
        if(mPlayer.isPlaying()) {
            mPlayer.pause();
        }
}

我知道这是一个奇怪而具体的答案,但也许其他有同样挣扎的人可以找出他或她遇到问题的原因.

I know this is a weird and specific answer, but maybe someone else who had the same struggle can find out why he or she was having problems.

祝大家度过愉快的一天,感谢您的帮助

Have a great day all and thanks for trying to help

~Waro(dh19,可惜不能用waro)

~Waro (dh19, couldnt use waro sadly)

这篇关于媒体播放器错误 (-38,0) 和错误 (1,-1010)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆