Should a MediaPlayer run in separate thread? Should a MediaPlayer run in separate thread? multithreading multithreading

Should a MediaPlayer run in separate thread?


Unfortunately, calling prepareAsync() is simply not good enough to avoid ANR prompts and your application hanging for a few seconds, especially if you're playing a file from the network. Your best bet is to put your MediaPlayer instance in its own thread, or at the very least execute intensive calls in a Handler (like mediaplayer.start()). I've been using MediaPlayer for over a year and I can tell you it definitely hangs after various calls, depending on the circumstances.


Could the streaming music be causing the main thread to stop until the music has finished streaming? This could be why it is slowing it right down.

I'm no expert and am currently learning myself, but it's worth thinking about.


No if you are doing any network transfer you should keep that in a thread, mediaplayer is not that resource intensive. Keep it on your activity.