Android media server Parsing 1-media player service structure, android1-media
The following is one of the four services registered by media server: structure diagram of MediaPlayerService
1. In the figure, the proxy object BpMediaPlayerService of MediaPlayerService is not found. For this part, refer to the Binder proxy object acquisition.
2. The figure mainly shows the MediaPlayer part of MeidaPlayerService. It can be seen that the MediaPlayer is created and the proxy object is obtained, if you have a wealth of imagination, you can basically guess the playing process of the MediaPlayer.
3. The next Weibo Post hopes to analyze the audio-related items during MediaPlayer playback.
4. If you cannot see or understand the figure, please contact us via email.
Why does android use service to play mediaplayer?
The activity you mentioned is actually executed in the background by default, so your concert is always running, but if I want to disable the activity and remove it from the system process directly, then you won't hear your music. Why do we need to open a service? Most people tend to do this. In the general programming mode mvc, most people tend to put service-oriented functions in the background for running. The service also has its specific functions, which can be separated from the activity or separately.
Android judges that the mediaplayer has been played in the service.
Add a listener for the MediaPlayer object after playing:
MMediaPlayer. setOnCompletionListener (new OnCompletionListener (){
@ Override
Public void onCompletion (MediaPlayer mp ){
Log. d ("tag", "playback completed ");
// Add your own code as needed...
}
});