Search code examples
androidshoutcastgyroscopebackground-musicandroid-music-player

Android radio application stops playing when I turn the screen or when screensaver activates


I created an internet radio application which uses a SHOUTcast radio station and basically plays the predetermined internet radio station when I press Play button. It works fine but when I turn the screen the music pauses and I have to press Play again. It also pauses when the screen is locked after a while. How can I prevent the music to be stopped?

Thanks,


Solution

  • You have 2 issues: first, you are probably not properly handling the screen rotation/orientation changes. Take a look at this for some guidance on approaches to that. The second issue is that the network is probably being disconnected when the screen locks: you might need to grab a wake lock to prevent that or explicitly prohibit wifi sleeping. Take a look at this answer: How do I keep Wifi from disconnecting when phone is asleep? for some guidance on that.