Android background service doesn't play audio

128 views
Skip to first unread message

Ish Rash

unread,
Dec 21, 2018, 4:57:31 AM12/21/18
to Kivy users support
I'm trying to play an audio file from the background service but it doesn't play it. The log says it does for a while and stop but the audio can't be heard.

The service is called when the app is paused:

from jnius import autoclass
service
= autoclass('{}.Service{}'.format('kivyapp.music', 'S1'))
mActivity
= autoclass('org.kivy.android.PythonActivity').mActivity
argument
= ''
service
.start(mActivity, argument)


/service/main.py

from jnius import autoclass
MediaPlayer = autoclass('android.media.MediaPlayer')
AudioManager = autoclass('android.media.AudioManager')

if __name__ == '__main__':
    nowPlaying
= MediaPlayer()
    nowPlaying
.setDataSource('music00.mp3')
    nowPlaying
.prepare()
    nowPlaying
.setLooping(False)
    nowPlaying
.setVolume(0.5, 0.5)
    nowPlaying
.start()



I would like to know if I'm doing something wrong. Thank you. 
Log.txt attached
log.txt

ZenCODE

unread,
Dec 22, 2018, 9:08:28 AM12/22/18
to Kivy users support
Have you confirmed that the audio can be heard if played from the app normally?
Message has been deleted

Ish Rash

unread,
Dec 22, 2018, 11:53:10 AM12/22/18
to Kivy users support
Yes, everything works in the app

ZenCODE

unread,
Dec 22, 2018, 4:26:28 PM12/22/18
to Kivy users support
Hmm. Tricky. The only thing I can suggest is to do a detailed comparison between the log when the audio plays from the main app, and the log when it does not from the service. The line

    EffectDescriptor: setEffectEnabled(true) CPU Load limit exceeded for Fx MySpace, CPU 7.500000 MIPS

is the only thing that seems to stand out. Does it occur when the audio plays form the main app? Comparing the logs seems the only way to get a clue as to why it does not work....

Ish Rash

unread,
Jan 4, 2019, 4:24:11 AM1/4/19
to Kivy users support
Sorry for the late reply. I did compare them but couldn't find it.


I think the main problem was that, MediaPlayer didn't like me requesting for getCurrentPosition() every second. Also adding :sticky to my buildozer services = service:service.py seems to solve the problem.


Following these steps also helped.



Reply all
Reply to author
Forward
0 new messages