stop playing media if we seek to an asset that is not remote

This commit is contained in:
bwees 2025-06-02 14:56:40 -05:00
parent a097369466
commit 892e6d93a1
No known key found for this signature in database
4 changed files with 18 additions and 0 deletions

View File

@ -20,6 +20,7 @@ abstract interface class ICastDestinationService {
void play();
void pause();
void seekTo(Duration position);
void stop();
Future<void> disconnect();
Future<List<(String, CastDestinationType, dynamic)>> getDevices();

View File

@ -130,6 +130,7 @@ class GalleryViewerPage extends HookConsumerWidget {
if (isCasting) {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (context.mounted) {
ref.read(castProvider.notifier).stop();
context.scaffoldMessenger.showSnackBar(
SnackBar(
duration: const Duration(seconds: 1),
@ -398,6 +399,7 @@ class GalleryViewerPage extends HookConsumerWidget {
context.scaffoldMessenger.clearSnackBars();
if (isCasting) {
ref.read(castProvider.notifier).stop();
context.scaffoldMessenger.showSnackBar(
SnackBar(
duration: const Duration(seconds: 2),

View File

@ -83,6 +83,10 @@ class CastNotifier extends StateNotifier<CastManagerState> {
_gCastService.seekTo(position);
}
void stop() {
_gCastService.stop();
}
Future<void> disconnect() async {
await _gCastService.disconnect();
}

View File

@ -263,6 +263,17 @@ class GCastService implements ICastDestinationService {
});
}
@override
void stop() {
_gCastRepository.sendMessage(CastSession.kNamespaceMedia, {
"type": "STOP",
"mediaSessionId": _sessionId,
});
_mediaStatusPollingTimer?.cancel();
currentAssetId = null;
}
@override
Future<List<(String, CastDestinationType, dynamic)>> getDevices() async {
final dests = await _gCastRepository.listDestinations();