Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using IntentService for MediaPlayer playback

Is it reasonable to use an IntentService for background MediaPlayer playback on demand? According to the developer's guide an IntentService lasts only as long as it is doing actually work. Considering the resulting overhead of reinitializing the MediaPlayer everytime when I want to play a track again, it seems to be a bad Idea...

So my question is: How big is the actual resulting overhead using this kind of Service. Would it have a perceptable impact on the system's/application's performance? Should I use my own implementation of Service with a dedicated worker thread instead?

like image 336
wodzu Avatar asked Aug 08 '13 11:08

wodzu


1 Answers

Is it reasonable to use an IntentService for background MediaPlayer playback on demand?

IMHO, no, because you can't really change tracks this way. Moreover, you need to know when the track completes, and you can't do that this way, except by leaking memory. Finally, it means that Android will terminate your process, possibly milliseconds after onHandleIntent() ends, which makes for a useless music player.

Should I use my own implementation of Service with a dedicated worker thread instead?

You may not need a thread, as much of MediaPlayer is already asynchronous. Only if you would be doing network I/O or disk I/O or something on your own might you want your own thread. But having a Service -- and probably a foreground Service -- is the typical approach for a music player.

like image 128
CommonsWare Avatar answered Nov 13 '22 12:11

CommonsWare