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

二次信任 提交于 2019-11-26 05:29:52

问题


When creating an instance of MediaPlayer LogCat shows this error:

QCMediaPlayer mediaplayer NOT present

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();
    }
}

回答1:


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

Check this sources to find out more details:

QCMediaPlayer.java




回答2:


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 MediaPlayer not by creating a new instance and setting the data source but by creating it using the static method create:

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

or

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



回答3:


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




回答4:


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!




回答5:


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.



来源:https://stackoverflow.com/questions/24501086/why-mediaplayer-throws-not-present-error-when-creating-instance-of-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!