Android 为什么 MediaPlayer 在创建它的实例时抛出 NOT present 错误?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24501086/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 08:17:59  来源:igfitidea点击:

Why MediaPlayer throws NOT present error when creating instance of it?

androidadtandroid-mediaplayerlogcat

提问by antifriz

When creating an instance of MediaPlayer LogCat shows this error:

创建 MediaPlayer LogCat 实例时显示此错误:

QCMediaPlayer mediaplayer NOT present

QCMediaPlayer 媒体播放器不存在

Why is that and is it normal?

为什么会这样,这正常吗?

Sample:

样本:

package com.example.testapp;

import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;



public class MainActivity extends Activity{


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        MediaPlayer mediaPlayer = new MediaPlayer();
    }
}

采纳答案by alexuz

It means your platform does not support QCMediaPlayer. QCMediaPlayer provides extended APIs and interfaces to get and set MPD attributes for DASH protocol in compatible Snapdragon builds. So, this error should not affect on media playing in normal case

这意味着您的平台不支持 QCMediaPlayer。QCMediaPlayer 提供扩展的 API 和接口,以在兼容的 Snapdragon 版本中获取和设置 DASH 协议的 MPD 属性。所以,这个错误应该不会影响正常情况下的媒体播放

Check this sources to find out more details:

查看此来源以了解更多详细信息:

QCMediaPlayer.java

QCMediaPlayer.java

回答by MikeL

I know that this is not an answer for "Why" this is happening but if someone wants to make it work (at least for me it worked), you can initialize the MediaPlayernot by creating a new instance and setting the data source but by creating it using the staticmethod create:

我知道这不是“为什么”发生这种情况的答案,但是如果有人想让它起作用(至少对我来说它起作用了),您可以MediaPlayer通过创建新实例并设置数据源来初始化not它使用的static方法create

MediaPlayer player = MediaPlayer.create(this, Uri.parse(sound_file_path));

or

或者

MediaPlayer player = MediaPlayer.create(this, soundRedId, loop);

回答by Harsh Chhabra

adding mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);solved problem for me. Initially I tried with other types however it didn't work.

mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);为我添加已解决的问题。最初我尝试使用其他类型,但它不起作用。

回答by Roga Men

I have added this code:

我已经添加了这个代码:

MediaPlayer mediaPlayer = MediaPlayer.create(MainActivity.this,R.raw.menumusic);
mediaPlayer.start();

And it was not working, what seemed to fix this for me is restarting Android Studio.
Hope this will help someone.

它不起作用,似乎对我来说解决这个问题的是重新启动 Android Studio
希望这会帮助某人。

回答by Shawn Lauzon

Bizarrely, what seemed to fix this for me is restarting Android Studio. Then I ran in debug mode and it started working, and haven't seen the error since. Weird!

奇怪的是,似乎对我来说解决这个问题的是重新启动 Android Studio。然后我在调试模式下运行,它开始工作,从那时起就没有看到错误。奇怪的!