MediaQueue: add itemChangedAtIndex stream
This commit is contained in:
parent
e21c695b42
commit
0b56a254ea
2 changed files with 25 additions and 1 deletions
|
|
@ -1,5 +1,8 @@
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_cast_framework/src/PlatformBridgeApis.dart';
|
import 'package:flutter_cast_framework/src/PlatformBridgeApis.dart';
|
||||||
|
import 'package:meta/meta.dart';
|
||||||
|
|
||||||
typedef MediaQueueItemsInsertedInRangeCallback = void Function(
|
typedef MediaQueueItemsInsertedInRangeCallback = void Function(
|
||||||
int insertIndex, int insertCount);
|
int insertIndex, int insertCount);
|
||||||
|
|
@ -11,7 +14,14 @@ typedef MediaQueueItemsReorderedAtIndexesCallback = void Function(
|
||||||
class MediaQueue {
|
class MediaQueue {
|
||||||
final CastHostApi _hostApi;
|
final CastHostApi _hostApi;
|
||||||
|
|
||||||
MediaQueue(this._hostApi);
|
MediaQueue(this._hostApi) {
|
||||||
|
this.itemUpdatedAtIndexStream =
|
||||||
|
this._itemUpdatedAtIndexStreamController.stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dispose() {
|
||||||
|
this._itemUpdatedAtIndexStreamController.close();
|
||||||
|
}
|
||||||
|
|
||||||
Future<int> getItemCount() {
|
Future<int> getItemCount() {
|
||||||
return _hostApi.getQueueItemCount();
|
return _hostApi.getQueueItemCount();
|
||||||
|
|
@ -41,4 +51,17 @@ class MediaQueue {
|
||||||
|
|
||||||
/// Called when one or more changes are about to be made to the queue.
|
/// Called when one or more changes are about to be made to the queue.
|
||||||
VoidCallback? onMediaQueueWillChange;
|
VoidCallback? onMediaQueueWillChange;
|
||||||
|
|
||||||
|
final _itemUpdatedAtIndexStreamController = StreamController<int>.broadcast();
|
||||||
|
late Stream<int> itemUpdatedAtIndexStream;
|
||||||
|
|
||||||
|
/// Internal method that shouldn't be visible
|
||||||
|
@internal
|
||||||
|
void dispatchItemUpdatedAtIndex(List<int?> indexes) {
|
||||||
|
indexes.forEach((i) {
|
||||||
|
if (i != null) {
|
||||||
|
this._itemUpdatedAtIndexStreamController.add(i);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -191,6 +191,7 @@ class _CastFlutterApiImplementor extends CastFlutterApi {
|
||||||
@override
|
@override
|
||||||
void itemsUpdatedAtIndexes(List<int?> indexes) {
|
void itemsUpdatedAtIndexes(List<int?> indexes) {
|
||||||
mediaQueue.onItemsUpdatedAtIndexes?.call(indexes);
|
mediaQueue.onItemsUpdatedAtIndexes?.call(indexes);
|
||||||
|
mediaQueue.dispatchItemUpdatedAtIndex(indexes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue