# AudioInteractionSample **Repository Path**: hadss/audio-interaction-sample ## Basic Information - **Project Name**: AudioInteractionSample - **Description**: 本场景解决方案主要面向前台音频开发人员。指导开发者基于AudioRenderer开发音频播控功能。功能包括后台播放、和播控中心的交互、适配不同类型的焦点打断策略、切换路由发声设备、切换输出设备等基础音频常见功能。 - **Primary Language**: TypeScript - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 47 - **Created**: 2024-10-12 - **Last Updated**: 2024-10-12 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Audio playback control and multi scene interaction based on AudioRenderer #### Brief Introduction This scenario solution is mainly aimed at front-end audio developers. Guide developers to develop audio playback control functions based on AudioRenderer. The functions include background playback, interaction with the broadcasting control center, adaptation to different types of focus interruption strategies, switching routing and sound devices, switching output devices and other basic audio common functions. #### Preview of renderings | Main page | Lyrics page | |--------------------------------------|---------------------------------------| | ![](screenshots/device/MainPage.png) | ![](screenshots/device/LyricPage.png) | #### Main module structure of the project ``` ├──entry/src/main/ets/ │ ├──common │ │ ├──constants // constants │ │ └──utils // constants │ ├──components // components │ │ ├──ControlAreaComponent.ets // Audio control area component │ │ ├──LyricsComponent.ets // Lyrics Component │ │ ├──MusicInfoComponent.ets // Music Content Component │ │ ├──PlayerInfoComponent.ets // Broadcast control content area component │ │ └──TopAreaComponent.ets // Top Area Component │ ├──dataSource // Source data │ │ ├──SongDataSource.ets // Song data │ │ └──SongListData.ets // Song List Data │ ├──entryability │ │ └──EntryAbility.ets // Ability's lifecycle callback content │ ├──entrybackupability │ │ └──EntryBackupAbility.ets // The lifecycle callback content of ExitBackupAbility │ ├──lyric // Lyrics function │ └──pages // pages ├──MediaService/src/main/ets │ ├──songDataController // Song information data │ │ ├──PlayerData.ets // Play data │ │ ├──SongData.ets // Song source data │ │ └──SongItemBuilder.ets // Song combination data │ └──utils │ ├──AudioRendererController.ets // Audio playback control │ ├──AVSessionController.ets // Media session control │ ├──BackgroundUtil.ets // Backend playback function │ ├──Logger.ets // Log function │ ├──MediaTools.ets // Media data conversion tool class │ └──PreferencesUtil.ets // Preferred storage function └──entry/src/main/resources // Application static resource directory ``` #### Related permissions 1. Background task permissions:ohos.permission.KEEP_BACKGROUND_RUNNING。 #### Rely on Not involved #### Constraints and limitations 1. This example only supports running on standard systems and supports devices such as Huawei phones. 2. HarmonyOS system: HarmonyOS Beta 1 or above. 3. DevEco Studio version: DevEco Studio NEXT Beta 1 and above. 4. HarmonyOS SDK version: HarmonyOS NEXT Beta1 SDK and above.