Using IntentService Playback for MediaPlayer

Is it possible to use IntentService playback for MediaPlayer background on demand? According to the developer's guide , IntentService lasts only as long as it really works. Given the overhead involved in reinitializing MediaPlayer every time I want to play the track again, this seems like a bad idea ...

So my question is: how big is the actual overhead gain using this type of Service . Will this have a tangible impact on system / application performance? Should I use my own implementation of Service with a dedicated workflow?

+6
source share
1 answer

Can I use an IntentService to play a background media player on demand?

IMHO, no, because you cannot change the tracks in this way. In addition, you need to know when the track ends, and you cannot do this, except for a memory leak. Finally, this means that Android will terminate your process, perhaps a millisecond after the end of onHandleIntent() , which will lead to a useless music player.

Should I use my own implementation of the Service with a dedicated workflow?

You may not need a thread since most of MediaPlayer already asynchronous. Only if you will do network I / O or an I / O drive or whatever you like, can you use your own thread. But having Service - and probably Service foreground - is a typical approach for a music player.

+11
source

Source: https://habr.com/ru/post/951306/


All Articles