Why Mediaplayer Throws Not Present Error When Creating Instance of It

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

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

Error in MediaPlayer : E/MediaPlayer: Error (1,-19) - Android

I solved the problem!

I changed the way I call the sound file, here's how I did it.

I put the file inside the assets in order to make it works.

    if(mp.isPlaying())
{
mp.stop();
}

try {
mp.reset();
AssetFileDescriptor afd;
afd = getAssets().openFd("AudioFile.mp3");
mp.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(),afd.getLength());
mp.prepare();
mp.start();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

I got this from here: android - how to make a button click play a sound file every time it been pressed?

Why do I get NullPointerException when trying to instantiate Mediaplayer? Android Kotlin

Often it is best to wait to use the activity as a context until later in the lifecycle when things have been set up (e.g. in onCreate) to avoid initialization order issues. For exampe:

class MainActivity : AppCompatActivity() {
private lateinit var soundGenerator : SoundGenerator

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
//...
soundGenerator = SoundGenerator(this)
}
}

Alternately, sometimes you can use applicationContext instead of the current activity as an appropriate context.



Related Topics



Leave a reply



Submit