1# Selecting an Appropriate Audio Stream Type
2
3[Audio stream](audio-kit-intro.md#introduction-to-audio-streams) types are crucial for determining the mode of audio playback and recording. For audio playback streams, the stream type is determined by [StreamUsage](../../reference/apis-audio-kit/js-apis-audio.md#streamusage). For audio recording streams, the stream type is determined by [SourceType](../../reference/apis-audio-kit/js-apis-audio.md#sourcetype8). These types pose a significant impact on volume control, audio focus management, and input/output device selection.
4
5To ensure that the audio behavior meets expectations and delivers a superior user experience, you need to select an appropriate audio stream type based on the use cases and requirements.
6
7This topic describes [typical audio stream types and their use cases](#typical-audio-stream-types-and-use-cases) and [their effects on audio services](#effects-of-audio-stream-types-on-audio-services). It also describes how to [set the audio stream type](#setting-the-audio-stream-type) when you use different methods to implement audio playback and recording.
8
9## Typical Audio Stream Types and Use Cases
10
11### Stream Types for Audio Playback
12
13The following table describes the typical stream types used for audio playback. The type is specified by [StreamUsage](../../reference/apis-audio-kit/js-apis-audio.md#streamusage).
14
15| Stream Type| Use Case|
16| ---------- | ---------- |
17| STREAM_USAGE_MUSIC | Music playback and other media scenarios, for example, using [SoundPool](../media/using-soundpool-for-playback.md) to play short sounds.|
18| STREAM_USAGE_MOVIE |  Playing various video content such as short videos, movies, and TV series.|
19| STREAM_USAGE_AUDIOBOOK | Playing audiobooks, news, and podcasts.|
20| STREAM_USAGE_GAME | In-game background scores and character dubbing, ensuring uninterrupted background music. It is recommended that you use **STREAM_USAGE_VOICE_COMMUNICATION** for in-game voice.|
21| STREAM_USAGE_NAVIGATION | Voice broadcast in navigation scenarios.|
22| STREAM_USAGE_VOICE_MESSAGE | Playing voice short messages.|
23| STREAM_USAGE_VOICE_COMMUNICATION | VoIP voice calls.|
24| STREAM_USAGE_ALARM | Playing alarms.|
25| STREAM_USAGE_RINGTONE | Playing ringtones for VoIP calls.|
26| STREAM_USAGE_NOTIFICATION | Playing notification tones and prompt tones.|
27
28### Stream Types for Audio Recording
29
30The following table describes the typical stream types used for audio recording. The type is specified by [SourceType](../../reference/apis-audio-kit/js-apis-audio.md#sourcetype8).
31
32| Stream Type| Use Case|
33| ---------- | ---------- |
34| SOURCE_TYPE_MIC | Common audio recording.|
35| SOURCE_TYPE_VOICE_COMMUNICATION | VoIP voice calls.|
36| SOURCE_TYPE_VOICE_MESSAGE | Recording voice short messages.|
37
38## Effects of Audio Stream Types on Audio Services
39
40Different stream types affect user experience in volume control and system performance in adjusting the audio focus and selecting input/output devices.
41
42### Volume Control
43
44The audio playback stream type (specified by [StreamUsage](../../reference/apis-audio-kit/js-apis-audio.md#streamusage)) determines the volume type (specified by [AudioVolumeType](../../reference/apis-audio-kit/js-apis-audio.md#audiovolumetype)) to which the audio stream belongs. Each volume type (such as **MEDIA**, **RINGTONE**, **ALARM**, and **VOICE_CALL**) has an independent volume value, which can be adjusted independently on the UI.
45
46The table below lists the mappings between the typical audio playback stream types and volume types.
47
48| Stream Type| Volume Type|
49| ---------- | ---------- |
50|  MUSIC, MOVIE, AUDIOBOOK, GAME| MEDIA|
51|  RINGTONE, NOTIFICATION| RINGTONE|
52| VOICE_COMMUNICATION | VOICE_CALL|
53| ALARM | ALARM|
54
55### Adjusting the Audio Focus
56
57The audio stream type plays a key role in audio focus management. Different types of audio streams have different default priorities and processing modes for the audio focus.
58
59When an application starts audio playback or recording, the system automatically applies for focus based on the audio stream type. This may interrupt or duck other audio streams. For details about the audio focus, see [Introduction to Audio Focus and Audio Session](audio-playback-concurrency.md).
60
61This section describes only how the typical audio stream types affect the audio focus.
62
63- When a Navigation stream starts playing, the Music stream that is playing will be ducked. After the Navigation stream ends, the volume of the Music stream will be restored.
64
65- When a Movie stream starts playing, the Music stream that is playing will be stopped. When the Movie stream ends, the Music stream will not be automatically resumed, and the corresponding application will not receive any resume notification.
66
67- When a VoiceCommunication stream starts, the Music stream that is playing will be paused. When the VoiceCommunication stream ends, the music application will receive a notification to resume the playback.
68
69- The Music stream and Game stream can be mixed and played concurrently without affecting each other.
70
71- When a VoiceMessage stream starts, the Music stream that is playing will be paused. When the VoiceMessage stream ends, the music application will receive a notification to resume the playback.
72
73### Selecting Input/Output Devices
74
75The system selects an input/output device based on the audio stream type.
76
77The following lists the input/output devices selected for the typical audio stream types.
78
79- For a MUSIC stream, the default output device is a speaker.
80
81- For a VoiceCommunication stream, the default input device is a microphone, and the default output device is an earpiece.
82
83- For an Alarm stream, the default output device is a speaker. If a Bluetooth headset is connected before an ALARM stream is played, the audio is output from both the speaker and Bluetooth headset.
84
85If the default input/output devices do not meet service requirements, you can call related APIs to change the devices. When [using AudioRenderer to develop audio playback](using-audiorenderer-for-playback.md), you can call [setDefaultOutputDevice](../../reference/apis-audio-kit/js-apis-audio.md#setdefaultoutputdevice12) to set the default sound device.
86
87## Setting the Audio Stream Type
88
89The application can implement audio playback or recording by using a plurality of methods. Therefore, manners of setting the audio stream type are also different.
90
91Common methods for setting the audio playback stream type are as follows:
92
93- **[Using AudioRenderer for Audio Playback](using-audiorenderer-for-playback.md)**
94
95   Pass [StreamUsage](../../reference/apis-audio-kit/js-apis-audio.md#streamusage) in [createAudioRenderer](../../reference/apis-audio-kit/js-apis-audio.md#audiocreateaudiorenderer8) to specify the stream type.
96
97   The **options** parameter in **createAudioRenderer** is of the **AudioRendererOptions** type and contains the **AudioRendererInfo** struct, in which **AudioRendererInfo.usage** specifies the stream type.
98
99- **[Using OHAudio for Audio Playback](using-ohaudio-for-playback.md)**
100
101  Pass [OH_AudioStream_Usage](../../reference/apis-audio-kit/_o_h_audio.md#oh_audiostream_usage) in [OH_AudioStreamBuilder_SetRendererInfo](../../reference/apis-audio-kit/_o_h_audio.md#oh_audiostreambuilder_setrendererinfo) to specify the stream type.
102
103- **[Using AVPlayer for Audio Playback (ArkTS)](../media/using-avplayer-for-playback.md)**
104
105  Set the **audioRendererInfo** [property](../../reference/apis-media-kit/js-apis-media.md#properties) of the AVPlayer. **AVPlayer.audioRendererInfo** is of the **audio.AudioRendererInfo** type. You can use **AudioRendererInfo.usage** to specify [StreamUsage](../../reference/apis-audio-kit/js-apis-audio.md#streamusage).
106
107  > **NOTE**
108  >
109  > The **audioRendererInfo** property of the AVPlayer can be set only in the initialized state.
110  >
111  > If the application does not set this property, the AVPlayer performs default processing. If the media source contains videos, the default value of **usage** is **STREAM_USAGE_MOVIE**. Otherwise, the default value of **usage** is **STREAM_USAGE_MUSIC**.
112
113- **[Using AVPlayer for Audio Playback (C/C++)](../media/using-ndk-avplayer-for-playback.md)**
114
115  Pass [OH_AudioStream_Usage](../../reference/apis-audio-kit/_o_h_audio.md#oh_audiostream_usage) in [OH_AVPlayer_SetAudioRendererInfo](../../reference/apis-media-kit/_a_v_player.md#oh_avplayer_setaudiorendererinfo) to specify the stream type.
116
117- **[Using SoundPool for Audio Playback](../media/using-soundpool-for-playback.md)**
118
119  Pass [StreamUsage](../../reference/apis-audio-kit/js-apis-audio.md#streamusage) in [createSoundPool](../../reference/apis-media-kit/js-apis-media.md#mediacreatesoundpool10) to specify the stream type.
120
121Common methods for setting the audio recording stream type are as follows:
122
123- **[Using AudioCapturer for Audio Recording](using-audiocapturer-for-recording.md)**
124
125  Pass [SourceType](../../reference/apis-audio-kit/js-apis-audio.md#sourcetype8) in [createAudioCapturer](../../reference/apis-audio-kit/js-apis-audio.md#audiocreateaudiocapturer8) to specify the stream type.
126
127   The **options** parameter in **createAudioCapturer** is of the **AudioCapturerOptions** type and contains **AudioCapturerInfo**, in which **AudioCapturerInfo.source** specifies the source type.
128
129- **[Using OHAudio for Audio Recording](using-ohaudio-for-recording.md)**
130
131  Pass [OH_AudioStream_SourceType](../../reference/apis-audio-kit/_o_h_audio.md#oh_audiostream_sourcetype) in [OH_AudioStreamBuilder_SetCapturerInfo](../../reference/apis-audio-kit/_o_h_audio.md#oh_audiostreambuilder_setcapturerinfo) to specify the stream type.
132
133- **[Using AVRecorder for Audio Recording](../media/using-avrecorder-for-recording.md)**
134
135  Pass [AudioSourceType](../../reference/apis-media-kit/js-apis-media.md#audiosourcetype9) [AVRecorder.prepare](../../reference/apis-media-kit/js-apis-media.md#prepare9-3) to specify the stream type.
136
137  The **config** parameter in **AVRecorder.prepare** is of the **AVRecorderConfig** type, in which **AVRecorderConfig.audioSourceType** specifies the audio source type.
138