5

I'm trying to play a playlist with the android media player. When one track ends; i stop the media player and init it again with the new one. Everytime i init the player I set the wake lock with this line;

mMediaPlayer.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK);

For testing; i start the player and lock my phone screen. After a couple of tracks; the player stops and cannot pass to the other track. When this happens i wait a couple of minutes more. Then when i open my phone screen; the player starts immediately.

Is there any posibility that the mediaplayer releases the wakelock somehow? May be between the track switching in the playlist when it stops? Is the "MediaPlayer.setWakeMode" proper way to do it when dealing with playlists? Or should i use "PowerManager" class directy?

This problem takes too much time to test. Thx in advance.

syloc
  • 4,569
  • 5
  • 34
  • 49
  • 2
    you could check whether you are holding wakelock using **adb shell dumpsys power** – nandeesh Sep 08 '12 at 09:30
  • hi @nandeesh, i checked it with "adb shell dumpsys power". There is this line; "mWakeLockState = ". There is no value. Does this mean no wake lock? – syloc Sep 08 '12 at 09:44
  • you should look for mlocks.size. If it is 0, then no wakelocks are held by applications – nandeesh Sep 08 '12 at 09:46
  • OK. There are two PARTIAL_WAKE_LOCKs. One is activated by media player and the other says; "StayOnWhilePluggedIn Partial". For testing it properly; can i disable the "StayOnWhilePluggedIn Partial" wake lock? – syloc Sep 08 '12 at 09:51
  • I think stayonwhilepluggedin is from Developer Options -> Stay awake. Though if the mediaplayer has stopped and your wakelock is held, the issue maybe with something else other than wakelock – nandeesh Sep 08 '12 at 09:53
  • Yes i disabled the "stay awake" option and the lock is gone. Now i just need to wait for the media player to stop again and check the wake lock... – syloc Sep 08 '12 at 10:01
  • Have you ever found a solution to this? I am currently facing the same problem right now – Dominik Seemayr Apr 02 '16 at 12:51
  • 1
    @DominikSeemayr I highly recommend examining the official test app from google. https://github.com/googlesamples/android-UniversalMusicPlayer – syloc Apr 06 '16 at 07:43
  • @syloc on what device does it happen? – Fedor Jan 28 '17 at 08:45

0 Answers0