Media Session framework and Android vehicle multimedia

Media Session framework and Android vehicle multimedia

Architecture of Multimedia Applications

Media Player: A bare bones player with support for the most common audio/video formats and data steams. Exo Player is an open source package that provides low-level audio APIs for Android. Exo Player provides high-performance features such as DASH and HLS streaming, while Media Player does not.As we all know, the most typical technique to keep music playing in the background of an application is to place the Player in the Service, and the Service offers a Binder to enable communication between the interface and the player.

If you encounter a lock screen, however, and want to communicate with the Service, you must use the AIDL interface/broadcast/Content Provider to complete the communication with other applications, and these communication methods not only increase communication between application developers. Communication expenses also enhance application coupling. To address the aforementioned issues, Android officially provides the Media Session framework beginning with Android5.0.

Framework for Media Sessions

The Media Session framework standardizes the communication interface between the interface and the player in audio and video applications, allowing total decoupling of the interface and the player. The Media Session framework defines two key classes: media session and media controller, which together provide a full technical basis for developing multimedia player applications.The media session and media controller communicate with one another via preset callbacks corresponding to typical player actions (play, pause, stop, etc.), as well as extensible custom calls that specify customized application behavior.

media event

All communication with the player is handled via the media session. It hides the API of the player from the rest of the program. Only from the media session that controls the player may the system invoke the player.A session keeps track of the player's status (playing/paused) as well as information about what is playing.

Callbacks from one or more media controllers can be received by a session. The app's UI and a partner device running Wear OS or Android Auto may operate your player in this manner. Response logic to callbacks must be consistent. Regardless of whatever client application triggered the callback, the response to the Media Session callback is the same.

media manager

The media controller's job is to isolate the interface; the interface's code only communicates with the media controller (not the player), and the media controller turns transfer control commands into media session callbacks. It also gets callbacks from the media session anytime the session state changes, allowing it to automatically update the related interface, and the media controller can only be linked to one media session at a time.You can deploy alternative interfaces and/or players at runtime when using media controllers and media sessions. This enables you to customize the app's look and/or performance according on the capabilities of the device on which it is running.

Overview

The Media Session framework is mainly used to solve the communication problem between the music interface and the service. It belongs to a typical C/S architecture. There are four commonly used member classes, namely Media Browser, Media Browser Service, Media Controller and Media Session, which are controlled by the entire Media Session framework process.

Deja tu comentario