Android music player in stream or user interface background

I am trying to create a simple Android application to play audio files from an SD card.
I have some problems understanding the Service. I will be specific, here are my questions.

  • The default service runs in the user interface thread, right? Only if it is executed in a separate process does it have a different thread, as well as a context, because it is a different process on the system (fork of the virtual machine instance).
  • Where should the class be MediaPlayer? In the background or in a user interface thread. As for the related services running in the user interface thread, does it make sense to create a binding to the service, and so on, if it works in the user interface thread? Only if we want to continue playing music in the background while activity (or any component of the user interface has been destroyed), but in this case MusicPlayer will occupy the entire stream of the user interface, even without the user interface visible to the user. I'm right?
  • I found many tutorials on how to create a simple audio player, some of which show how to work in a separate stream directly from the service, while others directly work in the service using a class IBinderthat simply returns an instance of Service.

Please explain this topic. I would appreciate any help. Thanks.

+4
source share
1 answer

, Android MediaPlayer, , . , , . MediaPlayer , prepare. , prepareAsync, .

MediaPlayer , .

MediaPlayer . , , Looper ( ). a MediaPlayer async.

, ANR start ( ). .

0

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


All Articles