Skip to content

Commit

Permalink
Merge branch 'fix/background_event_lag' into minor
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanheise committed Dec 31, 2022
2 parents 687a246 + bc96322 commit 764cbbf
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
1 change: 1 addition & 0 deletions just_audio_background/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## 0.0.1-beta.9

* Fix currentIndex stutter.
* Performance and lint fixes (@Zekfad).

## 0.0.1-beta.8
Expand Down
6 changes: 4 additions & 2 deletions just_audio_background/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This package plugs into [just_audio](https://pub.dev/packages/just_audio) to add background playback support and remote controls (notification, lock screen, headset buttons, smart watches, Android Auto and CarPlay). It supports the simple use case where an app has a single `AudioPlayer` instance.

If your app has more complex requirements, it is recommended that you instead use the [audio_service](https://pub.dev/packages/audio_service) package directly.
If your app has more complex requirements, it is recommended that you instead use the [audio_service](https://pub.dev/packages/audio_service) package directly (which just_audio_background is internally built on). This will give you greater control over which buttons to display in the notification and how you want them to behave, while also allowing you to use multiple audio player instances.

## Setup

Expand All @@ -15,7 +15,7 @@ dependencies:

```

Then add the following initialization code to your app's `main` method:
Then add the following initialization code to your app's `main` method (refer to the API documentation for the complete set of options):

```dart
Future<void> main() async {
Expand Down Expand Up @@ -91,6 +91,8 @@ Make the following changes to your project's `AndroidManifest.xml` file:

Note: when targeting Android 12 or above, you must set `android:exported` on each component that has an intent filter (the main activity, the service and the receiver). If the manifest merging process causes `"Instantiable"` lint warnings, use `tools:ignore="Instantiable"` (as above) to suppress them.

If your app has a requirement to use a FragmentActivity, you can replace `AudioServiceActivity` above with `AudioServiceFragmentActivity`. If your app needs to use a custom activity, you can also make your own activity class a subclass of either `AudioServiceActivity` or `AudioServiceFragmentActivity`. For more details on this and other options, refer to the [audio_service setup instructions](https://pub.dev/packages/audio_service).

## iOS setup

Insert this in your `Info.plist` file:
Expand Down
12 changes: 1 addition & 11 deletions just_audio_background/lib/just_audio_background.dart
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ class _JustAudioPlayer extends AudioPlayerPlatform {
final eventController = StreamController<PlaybackEventMessage>.broadcast();
final playerDataController = StreamController<PlayerDataMessage>.broadcast();
bool? _playing;
int? _index;
IcyMetadataMessage? _icyMetadata;
int? _androidAudioSessionId;
late final _PlayerAudioHandler _playerAudioHandler;
Expand All @@ -181,11 +180,6 @@ class _JustAudioPlayer extends AudioPlayerPlatform {
_androidAudioSessionId = event['value'] as int?;
broadcastPlaybackEvent();
break;
case 'currentIndex':
_index = event['value'] as int?;
// The event is broadcast in response to the next mediaItem update
// which happens immediately after this.
break;
}
});
_audioHandler.mediaItem.listen((mediaItem) {
Expand Down Expand Up @@ -218,7 +212,7 @@ class _JustAudioPlayer extends AudioPlayerPlatform {
bufferedPosition: playbackState.bufferedPosition,
icyMetadata: _icyMetadata,
duration: _playerAudioHandler.currentMediaItem?.duration,
currentIndex: _index,
currentIndex: playbackState.queueIndex,
androidAudioSessionId: _androidAudioSessionId,
));
if (playbackState.playing != _playing) {
Expand Down Expand Up @@ -404,10 +398,6 @@ class _PlayerAudioHandler extends BaseAudioHandler
currentQueue![index!].copyWith(duration: track.duration);
queue.add(currentQueue!);
}
customEvent.add({
'type': 'currentIndex',
'value': track.index,
});
mediaItem.add(currentMediaItem!);
}
});
Expand Down

0 comments on commit 764cbbf

Please sign in to comment.