Audio playback is a common scenario in media development. HarmonyOS NEXT offers a variety of implementation methods for audio playback. To help you quickly understand audio playback capabilities and select the appropriate solution based on audio formats and service scenarios, the following development practice guides are provided:
- PCM Audio Playback Using AudioRender: AudioRender provides ArkTS APIs for audio playback and supports only PCM format. This guide demonstrates how to implement PCM playback using AudioRender, covering scenarios such as basic playback controls, precise seeking, muted playback, speed adjustment, volume control, focus management, background playback with media controller integration, and cold start.
- PCM Audio Playback Using OHAudio: OHAudio provides native APIs for audio playback and supports only PCM format. This guide demonstrates how to implement PCM playback using OHAudio, covering scenarios such as basic playback controls, precise seeking, muted playback, speed adjustment, volume control, focus management, background playback with media controller integration, and cold start.
- Formatted Audio Playback Using AVPlayer (ArkTS): AVPlayer supports formatted audio such as WAV, MP3, and FLAC, offering both ArkTS and native APIs. This guide demonstrates how to implement formatted audio playback using the ArkTS APIs of AVPlayer, covering scenarios such as basic playback controls, precise seeking, muted playback, speed adjustment, volume control, focus management, background playback with media controller integration, and cold start.
- Formatted Audio Playback Using AVPlayer (C++): This guide demonstrates how to implement formatted audio playback using the native APIs of AVPlayer, covering scenarios such as basic playback controls, precise seeking, muted playback, speed adjustment, volume control, focus management, background playback with media controller integration, and cold start.
- Short Audio Playback Using SoundPool: SoundPool is designed for short audio effects, such as app startup sounds or notification tones. With SoundPool called, the app only needs to provide the audio source without handling data parsing or decoding. This guide helps you implement short audio playback using SoundPool, covering scenarios such as basic playback, speed adjustment, loop playback, and volume adjustment.