diff --git a/android/src/main/java/com/gianlucaparadise/flutter_cast_framework/PlatformBridgeApis.java b/android/src/main/java/com/gianlucaparadise/flutter_cast_framework/PlatformBridgeApis.java index ec3dcba..ee03f8a 100644 --- a/android/src/main/java/com/gianlucaparadise/flutter_cast_framework/PlatformBridgeApis.java +++ b/android/src/main/java/com/gianlucaparadise/flutter_cast_framework/PlatformBridgeApis.java @@ -356,6 +356,7 @@ public class PlatformBridgeApis { public interface CastHostApi { void sendMessage(CastMessage message); void showCastDialog(); + void setMute(Boolean muted); void loadMediaLoadRequestData(MediaLoadRequestData request); MediaInfo getMediaInfo(); void play(); @@ -412,6 +413,30 @@ public class PlatformBridgeApis { channel.setMessageHandler(null); } } + { + BasicMessageChannel channel = + new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.CastHostApi.setMute", getCodec()); + if (api != null) { + channel.setMessageHandler((message, reply) -> { + Map wrapped = new HashMap<>(); + try { + ArrayList args = (ArrayList)message; + Boolean mutedArg = (Boolean)args.get(0); + if (mutedArg == null) { + throw new NullPointerException("mutedArg unexpectedly null."); + } + api.setMute(mutedArg); + wrapped.put("result", null); + } + catch (Error | RuntimeException exception) { + wrapped.put("error", wrapError(exception)); + } + reply.reply(wrapped); + }); + } else { + channel.setMessageHandler(null); + } + } { BasicMessageChannel channel = new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.CastHostApi.loadMediaLoadRequestData", getCodec()); diff --git a/android/src/main/kotlin/com/gianlucaparadise/flutter_cast_framework/FlutterCastFrameworkPlugin.kt b/android/src/main/kotlin/com/gianlucaparadise/flutter_cast_framework/FlutterCastFrameworkPlugin.kt index 429a0bc..aa959ac 100644 --- a/android/src/main/kotlin/com/gianlucaparadise/flutter_cast_framework/FlutterCastFrameworkPlugin.kt +++ b/android/src/main/kotlin/com/gianlucaparadise/flutter_cast_framework/FlutterCastFrameworkPlugin.kt @@ -219,7 +219,6 @@ class FlutterCastFrameworkPlugin : FlutterPlugin, MethodCallHandler, ActivityAwa } override fun onProgressUpdated(progressMs: Long, durationMs: Long) { - Log.d(TAG, "RemoteMediaClient - onProgressUpdated progress: $progressMs duration: $durationMs") flutterApi?.onProgressUpdated(progressMs, durationMs) { } } } @@ -272,6 +271,12 @@ class FlutterCastFrameworkPlugin : FlutterPlugin, MethodCallHandler, ActivityAwa val remoteMediaClient: RemoteMediaClient = remoteMediaClient ?: return remoteMediaClient.stop() } + + override fun setMute(muted: Boolean?) { + if (muted == null) return + val castSession = mCastSession ?: return + castSession.isMute = muted + } } private fun getOnNamespaceResult(oldSession: CastSession?, newSession: CastSession?) = PlatformBridgeApis.CastFlutterApi.Reply> { namespaces -> diff --git a/ios/Classes/PlatformBridgeApis.h b/ios/Classes/PlatformBridgeApis.h index cd5bbee..a57052e 100644 --- a/ios/Classes/PlatformBridgeApis.h +++ b/ios/Classes/PlatformBridgeApis.h @@ -94,6 +94,7 @@ NSObject *CastHostApiGetCodec(void); @protocol CastHostApi - (void)sendMessageMessage:(CastMessage *)message error:(FlutterError *_Nullable *_Nonnull)error; - (void)showCastDialogWithError:(FlutterError *_Nullable *_Nonnull)error; +- (void)setMuteMuted:(NSNumber *)muted error:(FlutterError *_Nullable *_Nonnull)error; - (void)loadMediaLoadRequestDataRequest:(MediaLoadRequestData *)request error:(FlutterError *_Nullable *_Nonnull)error; - (nullable MediaInfo *)getMediaInfoWithError:(FlutterError *_Nullable *_Nonnull)error; - (void)playWithError:(FlutterError *_Nullable *_Nonnull)error; diff --git a/ios/Classes/PlatformBridgeApis.m b/ios/Classes/PlatformBridgeApis.m index 1860306..3b59396 100644 --- a/ios/Classes/PlatformBridgeApis.m +++ b/ios/Classes/PlatformBridgeApis.m @@ -306,6 +306,26 @@ void CastHostApiSetup(id binaryMessenger, NSObject) { + if (castSession == nil) { + return + } + let isMuted = muted == 1 + castSession?.setDeviceMuted(isMuted) + } + // MARK: - GCKSessionManagerListener // onSessionSuspended diff --git a/lib/src/PlatformBridgeApis.dart b/lib/src/PlatformBridgeApis.dart index a911751..db572db 100644 --- a/lib/src/PlatformBridgeApis.dart +++ b/lib/src/PlatformBridgeApis.dart @@ -311,6 +311,29 @@ class CastHostApi { } } + Future setMute(bool arg_muted) async { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.CastHostApi.setMute', codec, binaryMessenger: _binaryMessenger); + final Map? replyMap = + await channel.send([arg_muted]) as Map?; + if (replyMap == null) { + throw PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel.', + details: null, + ); + } else if (replyMap['error'] != null) { + final Map error = (replyMap['error'] as Map?)!; + throw PlatformException( + code: (error['code'] as String?)!, + message: error['message'] as String?, + details: error['details'], + ); + } else { + return; + } + } + Future loadMediaLoadRequestData(MediaLoadRequestData arg_request) async { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.CastHostApi.loadMediaLoadRequestData', codec, binaryMessenger: _binaryMessenger); diff --git a/pigeon/PlatformBridgeApisDefinition.dart b/pigeon/PlatformBridgeApisDefinition.dart index a257c1f..e653546 100644 --- a/pigeon/PlatformBridgeApisDefinition.dart +++ b/pigeon/PlatformBridgeApisDefinition.dart @@ -221,11 +221,15 @@ class CastMessage { abstract class CastHostApi { void sendMessage(CastMessage message); void showCastDialog(); + void setMute(bool muted); + + //region RemoteMediaClient void loadMediaLoadRequestData(MediaLoadRequestData request); MediaInfo getMediaInfo(); void play(); void pause(); void stop(); + //endregion } @FlutterApi()