Lines Matching refs:audio
9 next.link=audio-output.html
34 <p>With multiple apps potentially playing audio it's important to think about how they should
35 interact. To avoid every music app playing at the same time, Android uses audio focus to moderate
36 audio playback—only apps that hold the audio focus should play audio.</p>
38 <p>Before your app starts playing audio it should request—and receive—the audio focus.
39 Likewise, it should know how to listen for a loss of audio focus and respond appropriately when that
45 <p>Before your app starts playing any audio, it should hold the audio focus for the stream
51 permanent audio focus. Request transient focus when you expect to play audio for only a short time
52 (for example when playing navigation instructions). Request permanent audio focus when you
53 plan to play audio for the foreseeable future (for example, when playing music).</p>
55 <p>The following snippet requests permanent audio focus on the music audio stream. You should
56 request the audio focus immediately before you begin playback, such as when the user presses
63 // Request audio focus for playback
83 // Abandon audio focus when playback complete
87 <p>When requesting transient audio focus you have an additional option: whether or not you want to
88 enable "ducking." Normally, when a well-behaved audio app loses audio focus it immediately
89 silences its playback. By requesting a transient audio focus that allows ducking you tell other
90 audio apps that it’s acceptable for them to keep playing, provided they lower their volume until the
94 // Request audio focus for playback
106 <p>Ducking is particularly suitable for apps that use the audio stream intermittently, such as for
109 <p>Whenever another app requests audio focus as described above, its choice between permanent and
110 transient (with or without support for ducking) audio focus is received by the listener you
116 <p>If your app can request audio focus, it follows that it will in turn lose that focus when another
117 app requests it. How your app responds to a loss of audio focus depends on the manner of that
121 onAudioFocusChange()} callback method of they audio focus change listener you registered when
122 requesting audio focus receives a parameter that describes the focus change event. Specifically,
126 <p>Generally speaking, a transient (temporary) loss of audio focus should result in your app
127 silencing it’s audio stream, but otherwise maintaining the same state. You should continue to
128 monitor changes in audio focus and be prepared to resume playback where it was paused once you’ve
131 <p>If the audio focus loss is permanent, it’s assumed that another application is now being used to
132 listen to audio and your app should effectively end itself. In practical terms, that means stopping
133 playback, removing media button listeners—allowing the new audio player to exclusively handle
134 those events—and abandoning your audio focus. At that point, you would expect a user action
135 (pressing play in your app) to be required before you resume playing audio.</p>
137 <p>In the following code snippet, we pause the playback or our media player object if the audio
139 unregisters our media button event receiver and stops monitoring audio focus changes.<p>
157 <p>In the case of a transient loss of audio focus where ducking is permitted, rather than pausing
163 <p>Ducking is the process of lowering your audio stream output volume to make transient audio from
164 another app easier to hear without totally disrupting the audio from your own application.</p>
181 <p>A loss of audio focus is the most important broadcast to react to, but not the only one. The
182 system broadcasts a number of intents to alert you to changes in user’s audio experience.