From 47d321b500fc3767384698619c37e0b434f3e6c6 Mon Sep 17 00:00:00 2001 From: Ryan Heise Date: Tue, 28 Jun 2022 02:23:01 +1000 Subject: [PATCH 1/3] Support offload scheduling on Android. --- just_audio/CHANGELOG.md | 4 ++++ .../main/java/com/ryanheise/just_audio/AudioPlayer.java | 9 ++++++++- .../com/ryanheise/just_audio/MainMethodCallHandler.java | 2 +- just_audio/lib/just_audio.dart | 7 ++++++- just_audio/pubspec.yaml | 4 ++-- just_audio_background/pubspec.yaml | 2 +- just_audio_web/pubspec.yaml | 2 +- 7 files changed, 23 insertions(+), 7 deletions(-) diff --git a/just_audio/CHANGELOG.md b/just_audio/CHANGELOG.md index e3a9f7d37..94c13f6f8 100644 --- a/just_audio/CHANGELOG.md +++ b/just_audio/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.9.27 + +* Support offload scheduling on Android. + ## 0.9.26 * Auto-correct invalid HTTP headers in proxy. diff --git a/just_audio/android/src/main/java/com/ryanheise/just_audio/AudioPlayer.java b/just_audio/android/src/main/java/com/ryanheise/just_audio/AudioPlayer.java index de6df34fc..d31c284d2 100644 --- a/just_audio/android/src/main/java/com/ryanheise/just_audio/AudioPlayer.java +++ b/just_audio/android/src/main/java/com/ryanheise/just_audio/AudioPlayer.java @@ -11,6 +11,7 @@ import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.DefaultLivePlaybackSpeedControl; import com.google.android.exoplayer2.DefaultLoadControl; +import com.google.android.exoplayer2.DefaultRenderersFactory; import com.google.android.exoplayer2.ExoPlaybackException; import com.google.android.exoplayer2.LivePlaybackSpeedControl; import com.google.android.exoplayer2.LoadControl; @@ -90,6 +91,7 @@ public class AudioPlayer implements MethodCallHandler, Player.Listener, Metadata private int errorCount; private AudioAttributes pendingAudioAttributes; private LoadControl loadControl; + private boolean offloadSchedulingEnabled; private LivePlaybackSpeedControl livePlaybackSpeedControl; private List rawAudioEffects; private List audioEffects = new ArrayList(); @@ -132,9 +134,10 @@ public void run() { } }; - public AudioPlayer(final Context applicationContext, final BinaryMessenger messenger, final String id, Map audioLoadConfiguration, List rawAudioEffects) { + public AudioPlayer(final Context applicationContext, final BinaryMessenger messenger, final String id, Map audioLoadConfiguration, List rawAudioEffects, Boolean offloadSchedulingEnabled) { this.context = applicationContext; this.rawAudioEffects = rawAudioEffects; + this.offloadSchedulingEnabled = offloadSchedulingEnabled != null ? offloadSchedulingEnabled : false; methodChannel = new MethodChannel(messenger, "com.ryanheise.just_audio.methods." + id); methodChannel.setMethodCallHandler(this); eventChannel = new BetterEventChannel(messenger, "com.ryanheise.just_audio.events." + id); @@ -727,7 +730,11 @@ private void ensurePlayerInitialized() { if (livePlaybackSpeedControl != null) { builder.setLivePlaybackSpeedControl(livePlaybackSpeedControl); } + if (offloadSchedulingEnabled) { + builder.setRenderersFactory(new DefaultRenderersFactory(context).setEnableAudioOffload(true)); + } player = builder.build(); + player.experimentalSetOffloadSchedulingEnabled(offloadSchedulingEnabled); setAudioSessionId(player.getAudioSessionId()); player.addListener(this); } diff --git a/just_audio/android/src/main/java/com/ryanheise/just_audio/MainMethodCallHandler.java b/just_audio/android/src/main/java/com/ryanheise/just_audio/MainMethodCallHandler.java index e339df5c5..ac039d0f0 100644 --- a/just_audio/android/src/main/java/com/ryanheise/just_audio/MainMethodCallHandler.java +++ b/just_audio/android/src/main/java/com/ryanheise/just_audio/MainMethodCallHandler.java @@ -34,7 +34,7 @@ public void onMethodCall(MethodCall call, @NonNull Result result) { break; } List rawAudioEffects = call.argument("androidAudioEffects"); - players.put(id, new AudioPlayer(applicationContext, messenger, id, call.argument("audioLoadConfiguration"), rawAudioEffects)); + players.put(id, new AudioPlayer(applicationContext, messenger, id, call.argument("audioLoadConfiguration"), rawAudioEffects, call.argument("androidOffloadSchedulingEnabled"))); result.success(null); break; } diff --git a/just_audio/lib/just_audio.dart b/just_audio/lib/just_audio.dart index e25a43b18..235418a40 100644 --- a/just_audio/lib/just_audio.dart +++ b/just_audio/lib/just_audio.dart @@ -61,6 +61,8 @@ class AudioPlayer { final AudioLoadConfiguration? _audioLoadConfiguration; + final bool _androidOffloadSchedulingEnabled; + /// This is `true` when the audio player needs to engage the native platform /// side of the plugin to decode or play audio, and is `false` when the native /// resources are not needed (i.e. after initial instantiation and after [stop]). @@ -166,13 +168,15 @@ class AudioPlayer { bool handleAudioSessionActivation = true, AudioLoadConfiguration? audioLoadConfiguration, AudioPipeline? audioPipeline, + bool androidOffloadSchedulingEnabled = false, }) : _id = _uuid.v4(), _userAgent = userAgent, _androidApplyAudioAttributes = androidApplyAudioAttributes && _isAndroid(), _handleAudioSessionActivation = handleAudioSessionActivation, _audioLoadConfiguration = audioLoadConfiguration, - _audioPipeline = audioPipeline ?? AudioPipeline() { + _audioPipeline = audioPipeline ?? AudioPipeline(), + _androidOffloadSchedulingEnabled = androidOffloadSchedulingEnabled { _audioPipeline._setup(this); if (_audioLoadConfiguration?.darwinLoadControl != null) { _automaticallyWaitsToMinimizeStalling = _audioLoadConfiguration! @@ -1290,6 +1294,7 @@ class AudioPlayer { .map((audioEffect) => audioEffect._toMessage()) .toList() : [], + androidOffloadSchedulingEnabled: _androidOffloadSchedulingEnabled, ))) : (_idlePlatform = _IdleAudioPlayer(id: _id, sequenceStream: sequenceStream)); diff --git a/just_audio/pubspec.yaml b/just_audio/pubspec.yaml index 4ddd0250e..971eba931 100644 --- a/just_audio/pubspec.yaml +++ b/just_audio/pubspec.yaml @@ -1,6 +1,6 @@ name: just_audio description: A feature-rich audio player for Flutter. Loop, clip and concatenate any sound from any source (asset/file/URL/stream) in a variety of audio formats with gapless playback. -version: 0.9.26 +version: 0.9.27 homepage: https://github.com/ryanheise/just_audio/tree/master/just_audio environment: @@ -8,7 +8,7 @@ environment: flutter: ">=1.12.13+hotfix.5" dependencies: - just_audio_platform_interface: ^4.1.0 + just_audio_platform_interface: ^4.2.0 # just_audio_platform_interface: # path: ../just_audio_platform_interface just_audio_web: ^0.4.4 diff --git a/just_audio_background/pubspec.yaml b/just_audio_background/pubspec.yaml index aeaa3f4f3..314b81f9e 100644 --- a/just_audio_background/pubspec.yaml +++ b/just_audio_background/pubspec.yaml @@ -4,7 +4,7 @@ homepage: https://github.com/ryanheise/just_audio/tree/master/just_audio_backgro version: 0.0.1-beta.7 dependencies: - just_audio_platform_interface: ^4.1.0 + just_audio_platform_interface: ^4.2.0 # just_audio_platform_interface: # path: ../just_audio_platform_interface audio_service: ^0.18.6 diff --git a/just_audio_web/pubspec.yaml b/just_audio_web/pubspec.yaml index 80e1f96e2..0c5cd2dec 100644 --- a/just_audio_web/pubspec.yaml +++ b/just_audio_web/pubspec.yaml @@ -11,7 +11,7 @@ flutter: fileName: just_audio_web.dart dependencies: - just_audio_platform_interface: ^4.1.0 + just_audio_platform_interface: ^4.2.0 # just_audio_platform_interface: # path: ../just_audio_platform_interface flutter: From 2733991c0c9331c6141fba26b966a353faa7e728 Mon Sep 17 00:00:00 2001 From: Ryan Heise Date: Tue, 28 Jun 2022 21:29:37 +1000 Subject: [PATCH 2/3] Fix iOS documentation for non-HTTPS URLs and the proxy. --- just_audio/CHANGELOG.md | 1 + just_audio/README.md | 8 +++----- just_audio/example/ios/Runner/Info.plist | 12 +++++------- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/just_audio/CHANGELOG.md b/just_audio/CHANGELOG.md index 94c13f6f8..87f7140aa 100644 --- a/just_audio/CHANGELOG.md +++ b/just_audio/CHANGELOG.md @@ -1,6 +1,7 @@ ## 0.9.27 * Support offload scheduling on Android. +* Fix iOS documentation for non-HTTP URLS and proxy usage. ## 0.9.26 diff --git a/just_audio/README.md b/just_audio/README.md index eaf370f81..5a1fd46de 100644 --- a/just_audio/README.md +++ b/just_audio/README.md @@ -236,7 +236,7 @@ To allow your application to access audio files on the Internet, add the followi ``` -If you wish to connect to non-HTTPS URLS, also add the following attribute to the `application` element: +If you wish to connect to non-HTTPS URLS, or if you use a feature that depends on the proxy such as headers, caching or stream audio sources, also add the following attribute to the `application` element: ```xml @@ -284,15 +284,13 @@ post_install do |installer| end ``` -If you wish to connect to non-HTTPS URLS, add the following to your `Info.plist` file: +If you wish to connect to non-HTTPS URLS, or if you use a feature that depends on the proxy such as headers, caching or stream audio sources, add the following to your `Info.plist` file: ```xml NSAppTransportSecurity NSAllowsArbitraryLoads - NSAllowsArbitraryLoadsForMedia - ``` @@ -307,7 +305,7 @@ To allow your macOS application to access audio files on the Internet, add the f ``` -If you wish to connect to non-HTTPS URLS, add the following to your `Info.plist` file: +If you wish to connect to non-HTTPS URLS, or if you use a feature that depends on the proxy such as headers, caching or stream audio sources, add the following to your `Info.plist` file: ```xml NSAppTransportSecurity diff --git a/just_audio/example/ios/Runner/Info.plist b/just_audio/example/ios/Runner/Info.plist index a7d6daafb..efb7579f5 100644 --- a/just_audio/example/ios/Runner/Info.plist +++ b/just_audio/example/ios/Runner/Info.plist @@ -2,13 +2,11 @@ -NSAppTransportSecurity - - NSAllowsArbitraryLoads - - NSAllowsArbitraryLoadsForMedia - - + NSAppTransportSecurity + + NSAllowsArbitraryLoads + + CFBundleDevelopmentRegion $(DEVELOPMENT_LANGUAGE) CFBundleExecutable From cd7d330993126d37d3dc594beb79579aebfee31d Mon Sep 17 00:00:00 2001 From: Ryan Heise Date: Tue, 28 Jun 2022 22:36:37 +1000 Subject: [PATCH 3/3] Fix macOS documentation for non-HTTPS URLs and the proxy. --- just_audio/CHANGELOG.md | 2 +- just_audio/README.md | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/just_audio/CHANGELOG.md b/just_audio/CHANGELOG.md index 87f7140aa..565d5f934 100644 --- a/just_audio/CHANGELOG.md +++ b/just_audio/CHANGELOG.md @@ -1,7 +1,7 @@ ## 0.9.27 * Support offload scheduling on Android. -* Fix iOS documentation for non-HTTP URLS and proxy usage. +* Fix iOS/macOS documentation for non-HTTP URLS and proxy usage. ## 0.9.26 diff --git a/just_audio/README.md b/just_audio/README.md index 5a1fd46de..662b66faf 100644 --- a/just_audio/README.md +++ b/just_audio/README.md @@ -312,8 +312,6 @@ If you wish to connect to non-HTTPS URLS, or if you use a feature that depends o NSAllowsArbitraryLoads - NSAllowsArbitraryLoadsForMedia - ```