Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - MediaPlayer + PowerManager.PARTIAL_WAKE_LOCK

I'm creating application for listening radio streams via WiFi & 3G network.

I am using native MediaPlayer. Unfortunately when screen goes black and phone goes into standby mode mediaplayer starts stopping playing the music.

I have added:

mp.setWakeMode(myContext, PowerManager.PARTIAL_WAKE_LOCK);

But there wasn't almost any change (just stop playing and in the next 3 seconds start playing again..) only FULL_WAKE_LOCK and SCREEN_DIM_WAKE_LOCK is working as I expected...

In my device I have set option that prevents wifi to sleep.

I was trying to add my cusom WAKE_LOCK

        mp.setWakeMode(this.getBaseContext(), PowerManager.PARTIAL_WAKE_LOCK);
        wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "testa");
        wl.acquire();

But it didn't work as well. Only FULL_WAKE_LOCK works, but I do not want to drain battery with screen on :(.

I have HTC Desire with Android 2.2. Do you have any ideas how to prevent MediaPlayer stop playing internet radio stream while telephone is in standby mode?

like image 489
radzio Avatar asked Jul 24 '11 13:07

radzio


1 Answers

As Jerry points out, you may need to keep a WiFi lock is the stream is coming over WiFi. The other thing is, when are you acquiring the wakelock? You should acquire it when your app starts, not wait for the screen to go off. You may not be able to acquire the wakelock before the device goes to sleep. Also, you will need the WAKE_LOCK permission if you don't already have it.

like image 131
cyngus Avatar answered Sep 27 '22 17:09

cyngus