| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- 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<bool> _invokeBool(String method, [Object? arguments]) async {
- try {
- return await _channel.invokeMethod<bool>(method, arguments) ?? false;
- } on PlatformException {
- return false;
- } on MissingPluginException {
- return false;
- }
- }
- @override
- Future<bool> setQueue(JellyfinPlaybackQueue queue) {
- return _invokeBool('setQueue', queue.toMap());
- }
- @override
- Future<bool> play() => _invokeBool('play');
- @override
- Future<bool> pause() => _invokeBool('pause');
- @override
- Future<bool> next() => _invokeBool('next');
- @override
- Future<bool> previous() => _invokeBool('previous');
- @override
- Future<bool> seekToIndex(int index) {
- return _invokeBool('seekToIndex', {'index': index});
- }
- @override
- Future<bool> seek(Duration position) {
- return _invokeBool('seek', {'positionMs': position.inMilliseconds});
- }
- @override
- Future<bool> stop() => _invokeBool('stop');
- @override
- Future<bool> notificationPermissionGranted() {
- return _invokeBool('notificationPermissionGranted');
- }
- @override
- Future<bool> requestNotificationPermission() {
- return _invokeBool('requestNotificationPermission');
- }
- @override
- Future<JellyfinPlaybackSnapshot> getState() async {
- try {
- final raw = await _channel.invokeMethod<dynamic>('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() {}
- }
|