Audio Player stops suddenly in mid of playing music While using 'audio_service' in flutter

94 Views Asked by At

I am using audio_service package in flutter to play music in background when app is minimized, but I am facing a problem here when playing music, the problem is -

1 - When androidStopForegroundOnPause: false and stop() is not overridden in BaseHandler class - It work in all devices perfectly , expect we cant stop the background service from no where cause it
remain running in background always. like notification or wake screen.

2 - When androidStopForegroundOnPause: true, and stop() is not overridden in BaseHandler class - It does work working fine in android emulator with android 12 but not on android 12 physical device, it does plays music till 10 minutes and then stop the music player suddenly.

3 - When stop() is overridden in BaseHandler class(extended)

  • It does work working fine in android emulator with android 12 but not on android 12 physical device, it does plays music till 10 minutes and then stop the music player suddenly.(Same like case 2)

While Spotify and other music player doesn't even ask for battery optimization on my android 12 phone (stock android), and working fine it just when using this audio_service app

Please if anyone has workarounds to solve this problem tell me.

I also searched some threads on internet which is saying may be it is battery optimization problem but for me it wasn't working, I tried to set battery optimization Unrestricted for app but no effects. also audio_service is working fine with emulator device android 12 but not in physical device.

0

There are 0 best solutions below