• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Introduction to AVSession Kit
2<!--Kit: AVSession Kit-->
3<!--Subsystem: Multimedia-->
4<!--Owner: @ccfriend; @liao_qian-->
5<!--SE: @ccfriend-->
6<!--TSE: @chenmingxi1_huawei-->
7
8Audio and Video Session (AVSession) Kit provides the audio and video management service, which manages the playback behavior of all audio and video applications in the system in a unified manner. You can use the kit to quickly build unified audio and video display and control capabilities.
9
10## Capability Scope
11
12- Unified audio and video management: Audio and video applications access AVSession and send it application data (for example, the song that is being played and the playback state). Through a controller, the user can choose another application or device for playback.
13
14- Restricted audio background playback: After an audio application accesses AVSession, it can continue audio playback in the background. To use this feature, the application must also request a background task.
15
16## Highlights
17
18- Consistent user experience
19
20  Audio and video applications access AVSession and send it application data (for example, the song that is being played and the playback state).
21
22  Through a controller, the user can choose another application or device for playback.
23
24- Standardize background playback management
25
26  Through the controller, the background playback of applications is visible and controllable.
27
28  The system enforces strict control over background playback. For applications that have not integrated with AVSession or do not have a valid AVSession instance when they move to the background, their audio playback are forcibly paused. This prevents malicious applications from playing audio in the background.
29
30## Basic Concepts
31
32Be familiar with the following basic concepts before development:
33
34- AVSession
35
36  For AVSession, one end is the audio and video applications under control, and the other end is a controller (for example, Media Controller or AI Voice). AVSession provides a channel for information exchange between the application and controller.
37
38- Provider
39
40  An audio and video application that accesses the AVSession service. After accessing AVSession, the audio and video application must provide the media information, for example, the name of the item to play and the playback state, to AVSession. Through AVSession, the application also receives control commands from the controller and responds accordingly.
41
42- Controller
43
44  A system application that accesses AVSession to provide global control on audio and video playback behavior. Typical controllers are Media Controller and AI Voice. The following sections use Media Controller as an example of the controller. After accessing AVSession, the controller obtains the latest media information and sends control commands to the audio and video applications through AVSession.
45
46- AVSessionController
47
48  An object that controls the playback behavior of the provider. It obtains the playback information of the audio and video application and listens for the application playback changes to synchronize the AVSession information between the application and controller. The controller is the holder of an AVSessionController object.
49
50- AVSessionManager
51
52  An object that provides the capability of managing sessions. It can create an AVSession object, create an AVSessionController object, send control commands, and listen for session state changes.
53
54## AVSession Interaction Process
55
56AVSessions are classified into local AVSessions and distributed AVSessions.
57
58![AVSession Interaction Process](figures/avsession-interaction-process.png)
59
60- Local AVSession
61
62  Local AVSession establishes a connection between the provider and controller in the local device, so as to implement unified playback control and media information display for audio and video applications in the system.
63
64- Distributed AVSession
65
66  Distributed AVSession establishes a connection between the provider and controller in the cross-device scenario, so as to implement cross-device playback control and media information display for audio and video applications in the system. For example, you can project the content played on device A to device B and perform playback control on device B.
67
68## Constraints
69
70All audio and video applications that need to be played in the background must be connected to AVSession and background task management. Otherwise, audio playback is forcibly paused when such an application switches to the background.
71
72## Relationship with Related Kits
73
74To implement background playback, an application must use [Background Tasks Kit](../../task-management/background-task-overview.md) to request a continuous task to avoid being suspended.
75