From 30f2599230f484b3fdc7d05468ff3ea017b92d3f Mon Sep 17 00:00:00 2001 From: Ryan Heise Date: Sun, 29 May 2022 02:29:23 +1000 Subject: [PATCH] Fallback to constant bitrate seeking on Android. --- just_audio/CHANGELOG.md | 4 ++++ just_audio/README.md | 4 ++-- .../src/main/java/com/ryanheise/just_audio/AudioPlayer.java | 5 ++++- just_audio/example/lib/main.dart | 1 + just_audio/example/pubspec.yaml | 5 +---- just_audio/pubspec.yaml | 2 +- 6 files changed, 13 insertions(+), 8 deletions(-) diff --git a/just_audio/CHANGELOG.md b/just_audio/CHANGELOG.md index 37b72e083..45319fc91 100644 --- a/just_audio/CHANGELOG.md +++ b/just_audio/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.9.23 + +* Fallback to constant bitrate seeking on Android. + ## 0.9.22 * Migrate to Flutter 3, Xcode 13, ExoPlayer 2.17.1. diff --git a/just_audio/README.md b/just_audio/README.md index b63d6b63d..197f18303 100644 --- a/just_audio/README.md +++ b/just_audio/README.md @@ -384,15 +384,15 @@ The macOS player relies on server headers (e.g. `Content-Type`, `Content-Length` Windows support is enabled by adding an additional dependency to your `pubspec.yaml` alongside `just_audio`. There are a number of alternative options: * [just_audio_mpv](https://pub.dev/packages/just_audio_mpv) +* [just_audio_windows](https://pub.dev/packages/just_audio_windows) * [just_audio_libwinmedia](https://pub.dev/packages/just_audio_libwinmedia) -* [just_audio_windows](https://github.com/bdlukaa/just_audio/tree/master/just_audio_windows) (BETA - to supersede just_audio_libwinmedia) Example: ```yaml dependencies: just_audio: any # substitute version number - just_audio_libwinmedia: any # substitute version number + just_audio_windows: any # substitute version number ``` For issues with the Windows implementation, please open an issue on the respective implementation's GitHub issues page. 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 926cfb240..babeeba51 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 @@ -23,6 +23,7 @@ import com.google.android.exoplayer2.Timeline; import com.google.android.exoplayer2.TracksInfo; import com.google.android.exoplayer2.audio.AudioAttributes; +import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory; import com.google.android.exoplayer2.metadata.Metadata; import com.google.android.exoplayer2.metadata.MetadataOutput; import com.google.android.exoplayer2.metadata.icy.IcyHeaders; @@ -97,6 +98,7 @@ public class AudioPlayer implements MethodCallHandler, Player.Listener, Metadata private Map pendingPlaybackEvent; private ExoPlayer player; + private DefaultExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); private Integer audioSessionId; private MediaSource mediaSource; private Integer currentIndex; @@ -138,6 +140,7 @@ public AudioPlayer(final Context applicationContext, final BinaryMessenger messe eventChannel = new BetterEventChannel(messenger, "com.ryanheise.just_audio.events." + id); dataEventChannel = new BetterEventChannel(messenger, "com.ryanheise.just_audio.data." + id); processingState = ProcessingState.none; + extractorsFactory.setConstantBitrateSeekingEnabled(true); if (audioLoadConfiguration != null) { Map loadControlMap = (Map)audioLoadConfiguration.get("androidLoadControl"); if (loadControlMap != null) { @@ -587,7 +590,7 @@ private MediaSource decodeAudioSource(final Object json) { String id = (String)map.get("id"); switch ((String)map.get("type")) { case "progressive": - return new ProgressiveMediaSource.Factory(buildDataSourceFactory()) + return new ProgressiveMediaSource.Factory(buildDataSourceFactory(), extractorsFactory) .createMediaSource(new MediaItem.Builder() .setUri(Uri.parse((String)map.get("uri"))) .setTag(id) diff --git a/just_audio/example/lib/main.dart b/just_audio/example/lib/main.dart index 55e543a3f..862a65bc1 100644 --- a/just_audio/example/lib/main.dart +++ b/just_audio/example/lib/main.dart @@ -43,6 +43,7 @@ class MyAppState extends State with WidgetsBindingObserver { }); // Try to load audio from a source and catch any errors. try { + // AAC example: https://dl.espressif.com/dl/audio/ff-16b-2c-44100hz.aac await _player.setAudioSource(AudioSource.uri(Uri.parse( "https://s3.amazonaws.com/scifri-episodes/scifri20181123-episode.mp3"))); } catch (e) { diff --git a/just_audio/example/pubspec.yaml b/just_audio/example/pubspec.yaml index 1b4488e3f..4cc9e5cce 100644 --- a/just_audio/example/pubspec.yaml +++ b/just_audio/example/pubspec.yaml @@ -12,11 +12,8 @@ dependencies: rxdart: '^0.27.0' just_audio_mpv: ^0.1.1 # Other platform implementations below: + # just_audio_windows: ^0.1.0 # just_audio_libwinmedia: ^0.0.4 - # just_audio_windows: - # git: - # url: https://github.com/bdlukaa/just_audio.git - # path: just_audio_windows just_audio: path: ../ diff --git a/just_audio/pubspec.yaml b/just_audio/pubspec.yaml index df04f1670..66bbb24c3 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.22 +version: 0.9.23 homepage: https://github.com/ryanheise/just_audio/tree/master/just_audio environment: