Skip to content

Commit

Permalink
Merge branch 'Ruchit2759-fix_playFromSearch' into minor
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanheise committed Feb 6, 2024
2 parents ed3e485 + 67653a9 commit ed856d6
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 34 deletions.
1 change: 1 addition & 0 deletions audio_service/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 0.18.13

* Fix setAndroidPlaybackInfo call blocking (@julianscheel).
* Pass through missing extras to playFrom.../prepareFrom... (@Ruchit2759).

## 0.18.12

Expand Down
1 change: 1 addition & 0 deletions audio_service/example/lib/example_android13.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class MainScreen extends StatelessWidget {
final processingState =
snapshot.data ?? AudioProcessingState.idle;
return Text(
// ignore: deprecated_member_use
"Processing state: ${describeEnum(processingState)}");
},
),
Expand Down
1 change: 1 addition & 0 deletions audio_service/example/lib/example_multiple_handlers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ class MainScreen extends StatelessWidget {
final processingState =
snapshot.data ?? AudioProcessingState.idle;
return Text(
// ignore: deprecated_member_use
"Processing state: ${describeEnum(processingState)}");
},
),
Expand Down
1 change: 1 addition & 0 deletions audio_service/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class MainScreen extends StatelessWidget {
final processingState =
snapshot.data ?? AudioProcessingState.idle;
return Text(
// ignore: deprecated_member_use
"Processing state: ${describeEnum(processingState)}");
},
),
Expand Down
45 changes: 19 additions & 26 deletions audio_service/lib/audio_service.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore_for_file: close_sinks

import 'dart:async';
import 'dart:isolate';
import 'dart:ui';
Expand Down Expand Up @@ -963,7 +965,6 @@ class AudioService {
/// The root media ID for browsing the most recently played item(s).
static const String recentRootId = 'recent';

// ignore: close_sinks
static final BehaviorSubject<bool> _notificationClicked =
BehaviorSubject.seeded(false);

Expand Down Expand Up @@ -1013,21 +1014,21 @@ class AudioService {
}

static Future<void> _observeMediaItem() async {
Object? _artFetchOperationId;
Object? artFetchOperationId;
_handler.mediaItem.listen((mediaItem) async {
if (mediaItem == null) {
return;
}
final operationId = Object();
_artFetchOperationId = operationId;
artFetchOperationId = operationId;
final artUri = mediaItem.artUri;
if (artUri == null || artUri.scheme == 'content') {
_platform.setMediaItem(
SetMediaItemRequest(mediaItem: mediaItem._toMessage()));
} else {
/// Sends media item to the platform.
/// We potentially need to fetch the art before that.
Future<void> _sendToPlatform(String? filePath) async {
Future<void> sendToPlatform(String? filePath) async {
final extras = mediaItem.extras;
final platformMediaItem = mediaItem.copyWith(
extras: <String, dynamic>{
Expand All @@ -1040,35 +1041,35 @@ class AudioService {
}

if (artUri.scheme == 'file') {
_sendToPlatform(artUri.toFilePath());
sendToPlatform(artUri.toFilePath());
} else {
// Try to load a cached file from memory.
final fileInfo =
await cacheManager.getFileFromMemory(artUri.toString());
final filePath = fileInfo?.file.path;
if (operationId != _artFetchOperationId) {
if (operationId != artFetchOperationId) {
return;
}

if (filePath != null) {
// If we successfully downloaded the art call to platform.
_sendToPlatform(filePath);
sendToPlatform(filePath);
} else {
// We haven't fetched the art yet, so show the metadata now, and again
// after we load the art.
await _platform.setMediaItem(
SetMediaItemRequest(mediaItem: mediaItem._toMessage()));
if (operationId != _artFetchOperationId) {
if (operationId != artFetchOperationId) {
return;
}
// Load the art.
final loadedFilePath = await _loadArtwork(mediaItem);
if (operationId != _artFetchOperationId) {
if (operationId != artFetchOperationId) {
return;
}
// If we successfully downloaded the art, call to platform.
if (loadedFilePath != null) {
_sendToPlatform(loadedFilePath);
sendToPlatform(loadedFilePath);
}
}
}
Expand Down Expand Up @@ -1115,7 +1116,7 @@ class AudioService {
/// no slower than once every 200ms.
///
/// See [createPositionStream] for more control over the stream parameters.
static late final Stream<Duration> position = createPositionStream(
static final Stream<Duration> position = createPositionStream(
steps: 800,
minPeriod: const Duration(milliseconds: 16),
maxPeriod: const Duration(milliseconds: 200));
Expand All @@ -1137,7 +1138,6 @@ class AudioService {
assert(minPeriod <= maxPeriod);
assert(minPeriod > Duration.zero);
Duration? last;
// ignore: close_sinks
late StreamController<Duration> controller;
late StreamSubscription<MediaItem?> mediaItemSubscription;
late StreamSubscription<PlaybackState> playbackStateSubscription;
Expand Down Expand Up @@ -1511,7 +1511,7 @@ class AudioService {

/// Deprecated. Use [position] instead.
@Deprecated("Use position instead.")
static late final ValueStream<Duration> positionStream =
static final ValueStream<Duration> positionStream =
BehaviorSubject.seeded(Duration.zero, sync: true)
..addStream(position)
..stream;
Expand Down Expand Up @@ -2948,7 +2948,6 @@ class BaseAudioHandler extends AudioHandler {
/// The state changes broadcast via this stream can be listened to via the
/// Flutter app's UI
@override
// ignore: close_sinks
final BehaviorSubject<PlaybackState> playbackState =
BehaviorSubject.seeded(PlaybackState());

Expand All @@ -2969,7 +2968,6 @@ class BaseAudioHandler extends AudioHandler {
/// queueTitle.add(newTitle);
/// ```
@override
// ignore: close_sinks
final BehaviorSubject<String> queueTitle = BehaviorSubject.seeded('');

/// A controller for broadcasting the current media item to the app's UI,
Expand All @@ -2979,7 +2977,6 @@ class BaseAudioHandler extends AudioHandler {
/// mediaItem.add(item);
/// ```
@override
// ignore: close_sinks
final BehaviorSubject<MediaItem?> mediaItem = BehaviorSubject.seeded(null);

/// A controller for broadcasting the current [AndroidPlaybackInfo] to the app's UI,
Expand All @@ -2989,7 +2986,6 @@ class BaseAudioHandler extends AudioHandler {
/// androidPlaybackInfo.add(newPlaybackInfo);
/// ```
@override
// ignore: close_sinks
final BehaviorSubject<AndroidPlaybackInfo> androidPlaybackInfo =
BehaviorSubject();

Expand All @@ -3000,7 +2996,6 @@ class BaseAudioHandler extends AudioHandler {
/// ratingStyle.add(style);
/// ```
@override
// ignore: close_sinks
final BehaviorSubject<RatingStyle> ratingStyle = BehaviorSubject();

/// A controller for broadcasting a custom event to the app's UI.
Expand All @@ -3011,7 +3006,6 @@ class BaseAudioHandler extends AudioHandler {
/// customEventSubject.add(MyCustomEvent(arg: 3));
/// ```
@override
// ignore: close_sinks
final PublishSubject<dynamic> customEvent = PublishSubject<dynamic>();

/// A controller for broadcasting the current custom state to the app's UI.
Expand All @@ -3021,7 +3015,6 @@ class BaseAudioHandler extends AudioHandler {
/// customState.add(MyCustomState(...));
/// ```
@override
// ignore: close_sinks
final BehaviorSubject<dynamic> customState = BehaviorSubject<dynamic>();

/// Constructor. Normally this is called from subclasses via `super`.
Expand Down Expand Up @@ -3891,15 +3884,15 @@ class _HandlerCallbacks extends AudioHandlerCallbacks {

@override
Future<void> playFromMediaId(PlayFromMediaIdRequest request) async =>
(await handlerFuture).playFromMediaId(request.mediaId);
(await handlerFuture).playFromMediaId(request.mediaId, request.extras);

@override
Future<void> playFromSearch(PlayFromSearchRequest request) async =>
(await handlerFuture).playFromSearch(request.query);
(await handlerFuture).playFromSearch(request.query, request.extras);

@override
Future<void> playFromUri(PlayFromUriRequest request) async =>
(await handlerFuture).playFromUri(request.uri);
(await handlerFuture).playFromUri(request.uri, request.extras);

@override
Future<void> playMediaItem(PlayMediaItemRequest request) async =>
Expand All @@ -3911,15 +3904,15 @@ class _HandlerCallbacks extends AudioHandlerCallbacks {

@override
Future<void> prepareFromMediaId(PrepareFromMediaIdRequest request) async =>
(await handlerFuture).prepareFromMediaId(request.mediaId);
(await handlerFuture).prepareFromMediaId(request.mediaId, request.extras);

@override
Future<void> prepareFromSearch(PrepareFromSearchRequest request) async =>
(await handlerFuture).prepareFromSearch(request.query);
(await handlerFuture).prepareFromSearch(request.query, request.extras);

@override
Future<void> prepareFromUri(PrepareFromUriRequest request) async =>
(await handlerFuture).prepareFromUri(request.uri);
(await handlerFuture).prepareFromUri(request.uri, request.extras);

@override
Future<void> removeQueueItem(RemoveQueueItemRequest request) async =>
Expand Down
2 changes: 1 addition & 1 deletion audio_service/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ dev_dependencies:
sdk: flutter
mockito: ^5.0.0
fake_async: ^1.2.0
flutter_lints: ^1.0.4
flutter_lints: ^3.0.1

flutter:
plugin:
Expand Down
9 changes: 2 additions & 7 deletions audio_service/test/isolates_test.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore_for_file: close_sinks

import 'dart:isolate';

import 'package:audio_service/audio_service.dart';
Expand Down Expand Up @@ -265,7 +267,6 @@ void isolateEntryPoint(SendPort sendPort) {

class _MockAudioHandler implements BaseAudioHandler {
@override
// ignore: close_sinks
final BehaviorSubject<PlaybackState> playbackState =
BehaviorSubject.seeded(PlaybackState());

Expand All @@ -274,28 +275,22 @@ class _MockAudioHandler implements BaseAudioHandler {
BehaviorSubject.seeded(<MediaItem>[]);

@override
// ignore: close_sinks
final BehaviorSubject<String> queueTitle = BehaviorSubject.seeded('');

@override
// ignore: close_sinks
final BehaviorSubject<MediaItem?> mediaItem = BehaviorSubject.seeded(null);

@override
// ignore: close_sinks
final BehaviorSubject<AndroidPlaybackInfo> androidPlaybackInfo =
BehaviorSubject();

@override
// ignore: close_sinks
final BehaviorSubject<RatingStyle> ratingStyle = BehaviorSubject();

@override
// ignore: close_sinks
final PublishSubject<dynamic> customEvent = PublishSubject<dynamic>();

@override
// ignore: close_sinks
final BehaviorSubject<dynamic> customState = BehaviorSubject<dynamic>();

final Map<String, int> invocationCounts = {};
Expand Down

0 comments on commit ed856d6

Please sign in to comment.