@@ -70,6 +70,8 @@ class AudioPlayer {
7070
7171 final bool _androidOffloadSchedulingEnabled;
7272
73+ final AndroidAudioOffloadPreferences ? _androidAudioOffloadPreferences;
74+
7375 /// This is `true` when the audio player needs to engage the native platform
7476 /// side of the plugin to decode or play audio, and is `false` when the native
7577 /// resources are not needed (i.e. after initial instantiation and after [stop] ).
@@ -231,13 +233,18 @@ class AudioPlayer {
231233 /// next audio source on load errors, and will give up after [maxSkipsOnError]
232234 /// attempts. This is supported on Android, iOS and web. For other platforms,
233235 /// check the documentation of the respective platform implementation.
236+ ///
237+ /// [androidAudioOffloadPreferences] specifies whether audio offload is enabled
238+ /// on Android.
234239 AudioPlayer ({
235240 String ? userAgent,
236241 bool handleInterruptions = true ,
237242 bool androidApplyAudioAttributes = true ,
238243 bool handleAudioSessionActivation = true ,
239244 AudioLoadConfiguration ? audioLoadConfiguration,
240245 AudioPipeline ? audioPipeline,
246+ AndroidAudioOffloadPreferences ? androidAudioOffloadPreferences,
247+ @Deprecated ('Use androidAudioOffloadPreferences instead' )
241248 bool androidOffloadSchedulingEnabled = false ,
242249 bool useProxyForRequestHeaders = true ,
243250 bool useLazyPreparation = true ,
@@ -251,6 +258,7 @@ class AudioPlayer {
251258 _audioLoadConfiguration = audioLoadConfiguration,
252259 _audioPipeline = audioPipeline ?? AudioPipeline (),
253260 _androidOffloadSchedulingEnabled = androidOffloadSchedulingEnabled,
261+ _androidAudioOffloadPreferences = androidAudioOffloadPreferences,
254262 _useProxyForRequestHeaders = useProxyForRequestHeaders,
255263 // ignore: deprecated_member_use_from_same_package
256264 _playlist = ConcatenatingAudioSource ._playlist (
@@ -1640,6 +1648,8 @@ class AudioPlayer {
16401648 : [],
16411649 androidOffloadSchedulingEnabled:
16421650 _androidOffloadSchedulingEnabled,
1651+ androidAudioOffloadPreferences:
1652+ _androidAudioOffloadPreferences? ._toMessage (),
16431653 useLazyPreparation: _playlist.useLazyPreparation,
16441654 )))
16451655 : (_idlePlatform = _IdleAudioPlayer (
@@ -2360,6 +2370,47 @@ class AndroidLivePlaybackSpeedControl {
23602370 );
23612371}
23622372
2373+ /// Audio offload modes for Android.
2374+ enum AndroidAudioOffloadMode { disabled, enabled }
2375+
2376+ /// Audio offload preferences for Android.
2377+ ///
2378+ /// IMPORTANT: activation of audio offload depends on a negotiation between
2379+ /// ExoPlayer and the device to determine whether offload can be supported for a
2380+ /// given format and with given constraints (gapless, speed change). However,
2381+ /// several instances have been reported where the device incorrectly confirms
2382+ /// support for audio offload when it doesn't, and this can result in buggy
2383+ /// audio playback. Therefore, it is advised that you programmatically enable
2384+ /// audio offload only on device/OS combinations that you have tested and
2385+ /// verified to work.
2386+ class AndroidAudioOffloadPreferences {
2387+ /// The preferred audio offload mode.
2388+ final AndroidAudioOffloadMode audioOffloadMode;
2389+
2390+ /// Constrains enablement of audio offload to happen only if the device
2391+ /// can fulfill any gapless transitions that might exist in the playlist
2392+ /// during offload.
2393+ final bool isGaplessSupportRequired;
2394+
2395+ /// Constrains enablement of audio offload to happen only if the device
2396+ /// can fulfill any speed change request during offload.
2397+ final bool isSpeedChangeSupportRequired;
2398+
2399+ const AndroidAudioOffloadPreferences ({
2400+ this .audioOffloadMode = AndroidAudioOffloadMode .disabled,
2401+ this .isGaplessSupportRequired = false ,
2402+ this .isSpeedChangeSupportRequired = false ,
2403+ });
2404+
2405+ AndroidAudioOffloadPreferencesMessage _toMessage () =>
2406+ AndroidAudioOffloadPreferencesMessage (
2407+ audioOffloadMode:
2408+ AndroidAudioOffloadModeMessage .values[audioOffloadMode.index],
2409+ isGaplessSupportRequired: isGaplessSupportRequired,
2410+ isSpeedChangeSupportRequired: isSpeedChangeSupportRequired,
2411+ );
2412+ }
2413+
23632414class ProgressiveAudioSourceOptions {
23642415 final AndroidExtractorOptions ? androidExtractorOptions;
23652416 final DarwinAssetOptions ? darwinAssetOptions;
0 commit comments