import 'package:flutter/services.dart'; import '../models/jellyfin_playback.dart'; import 'jellyfin_playback_platform.dart'; /// MethodChannel implementation of the Media3 service. The Dart side never /// reads the token back; [JellyfinPlaybackQueue.toMap] carries it into the /// service and the native reporter keeps it in memory. class NativeJellyfinPlayback implements JellyfinPlaybackPlatform { static const _channel = MethodChannel( 'com.wasp.cardash_launcher/jellyfin_playback', ); Future _invokeBool(String method, [Object? arguments]) async { try { return await _channel.invokeMethod(method, arguments) ?? false; } on PlatformException { return false; } on MissingPluginException { return false; } } @override Future setQueue(JellyfinPlaybackQueue queue) { return _invokeBool('setQueue', queue.toMap()); } @override Future play() => _invokeBool('play'); @override Future pause() => _invokeBool('pause'); @override Future next() => _invokeBool('next'); @override Future previous() => _invokeBool('previous'); @override Future seekToIndex(int index) { return _invokeBool('seekToIndex', {'index': index}); } @override Future seek(Duration position) { return _invokeBool('seek', {'positionMs': position.inMilliseconds}); } @override Future stop() => _invokeBool('stop'); @override Future notificationPermissionGranted() { return _invokeBool('notificationPermissionGranted'); } @override Future requestNotificationPermission() { return _invokeBool('requestNotificationPermission'); } @override Future getState() async { try { final raw = await _channel.invokeMethod('getState'); if (raw is Map) { return JellyfinPlaybackSnapshot.fromMap(raw); } } on PlatformException { // The service may not be attached yet. } on MissingPluginException { // Widget tests and non-Android targets. } return JellyfinPlaybackSnapshot.empty; } @override void dispose() {} }