Skip to content

Commit

Permalink
Merge branch 'feature/offload_scheduling' into minor
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanheise committed Jun 28, 2022
2 parents 3db0316 + cd7d330 commit 3b5f1a7
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 21 deletions.
5 changes: 5 additions & 0 deletions just_audio/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.9.27

* Support offload scheduling on Android.
* Fix iOS/macOS documentation for non-HTTP URLS and proxy usage.

## 0.9.26

* Auto-correct invalid HTTP headers in proxy.
Expand Down
10 changes: 3 additions & 7 deletions just_audio/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ To allow your application to access audio files on the Internet, add the followi
<uses-permission android:name="android.permission.INTERNET"/>
```

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
<application ... android:usesCleartextTraffic="true">
Expand Down Expand Up @@ -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
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSAllowsArbitraryLoadsForMedia</key>
<true/>
</dict>
```

Expand All @@ -307,15 +305,13 @@ To allow your macOS application to access audio files on the Internet, add the f
<true/>
```

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
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSAllowsArbitraryLoadsForMedia</key>
<true/>
</dict>
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Object> rawAudioEffects;
private List<AudioEffect> audioEffects = new ArrayList<AudioEffect>();
Expand Down Expand Up @@ -132,9 +134,10 @@ public void run() {
}
};

public AudioPlayer(final Context applicationContext, final BinaryMessenger messenger, final String id, Map<?, ?> audioLoadConfiguration, List<Object> rawAudioEffects) {
public AudioPlayer(final Context applicationContext, final BinaryMessenger messenger, final String id, Map<?, ?> audioLoadConfiguration, List<Object> 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);
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void onMethodCall(MethodCall call, @NonNull Result result) {
break;
}
List<Object> 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;
}
Expand Down
12 changes: 5 additions & 7 deletions just_audio/example/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSAllowsArbitraryLoadsForMedia</key>
<true/>
</dict>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
Expand Down
7 changes: 6 additions & 1 deletion just_audio/lib/just_audio.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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]).
Expand Down Expand Up @@ -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!
Expand Down Expand Up @@ -1290,6 +1294,7 @@ class AudioPlayer {
.map((audioEffect) => audioEffect._toMessage())
.toList()
: [],
androidOffloadSchedulingEnabled: _androidOffloadSchedulingEnabled,
)))
: (_idlePlatform =
_IdleAudioPlayer(id: _id, sequenceStream: sequenceStream));
Expand Down
4 changes: 2 additions & 2 deletions just_audio/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
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:
sdk: ">=2.12.0 <3.0.0"
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
Expand Down
2 changes: 1 addition & 1 deletion just_audio_background/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion just_audio_web/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 3b5f1a7

Please sign in to comment.