Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MediaPlayer no longer working on the emulator since r10?

protected MediaPlayer _mediaPlayer;  

protected void playFromResource(int resId)     
    {     
    if (_mediaPlayer != null)         
        {         
        _mediaPlayer.stop();         
        _mediaPlayer.release();
        }     
    _mediaPlayer = MediaPlayer.create(this, resId);
    _mediaPlayer.start();
    }  

This code used to work fine on both the emulator and on devices. Since some time (I think it is since I updated to ADT r10) it only works on devices. On the emulator there is no sound anymore and the application freezes when it pass on _mediaPlayer.release() (the second time the function is called). I was able to keep the application from crashing by replacing the stop() and release() by reset() but it does not solve the main issue: There is no sound on the emulator.

the log file show me a bunch of these (only on the emulator) just after the call to start()

03-09 19:14:30.716: WARN/AudioTrack(34): obtainBuffer timed out (is the CPU pegged?) 0x1afb8 user=00001e00, server=00000600

Any clues ????

like image 486
Regis St-Gelais Avatar asked Mar 10 '11 12:03

Regis St-Gelais


People also ask

Why are emulators not working?

In Android Studio, go to File > Settings > Appearance & Behavior > System Settings > Android SDK . Select the SDK Tools tab and down the list make sure Intel x86 Emulator Accelerator (HAXM installer) is checked. If not, check the box, click Apply and install and restart Android Studio.

Why is the emulator in Android Studio not working?

If the emulator fails to launch due to the error vulkan-1. dll cannot be found , you probably need to update the emulator. To update the emulator in Android Studio, go to Tools > SDK Manager and install the latest stable version of Android platform.

How do I know if MediaPlayer is paused?

There is no API to check if MediaPlayer is paused or not. So please use any Boolean variable to check and toggle it when you paused using any button .


1 Answers

I had this problem on my MacBook Pro and found that I had to turn off my Bluetooth before launching the emulator.

like image 53
g_pass Avatar answered Sep 28 '22 03:09

g_pass