From 8f39ffe6a37f3a3af3435dd1f8fb4bcab721ef00 Mon Sep 17 00:00:00 2001 From: wang-bin Date: Mon, 28 Oct 2024 23:59:02 +0800 Subject: [PATCH] implement setMixWithOthers for iOS. #172 --- darwin/Classes/FvpPlugin.mm | 19 +++++++++++++++---- darwin/fvp.podspec | 2 ++ lib/src/video_player_mdk.dart | 5 ++++- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/darwin/Classes/FvpPlugin.mm b/darwin/Classes/FvpPlugin.mm index 469e177..269cf3f 100644 --- a/darwin/Classes/FvpPlugin.mm +++ b/darwin/Classes/FvpPlugin.mm @@ -5,10 +5,11 @@ #define USE_TEXCACHE 0 #import "FvpPlugin.h" -#import "Metal/Metal.h" -#import "CoreVideo/CoreVideo.h" #include "mdk/RenderAPI.h" #include "mdk/Player.h" +#import +#import +#import #include #include #include @@ -149,8 +150,8 @@ - (instancetype)initWithRegistrar:(NSObject*)registrar { - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { if ([call.method isEqualToString:@"CreateRT"]) { const auto handle = ((NSNumber*)call.arguments[@"player"]).longLongValue; - const auto width = (int)((NSNumber*)call.arguments[@"width"]).longLongValue; - const auto height = (int)((NSNumber*)call.arguments[@"height"]).longLongValue; + const auto width = ((NSNumber*)call.arguments[@"width"]).intValue; + const auto height = ((NSNumber*)call.arguments[@"height"]).intValue; auto player = make_shared(handle, width, height, _texRegistry); players[player->textureId()] = player; result(@(player->textureId())); @@ -159,6 +160,16 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { [_texRegistry unregisterTexture:texId]; players.erase(texId); result(nil); + } else if ([call.method isEqualToString:@"MixWithOthers"]) { + [[maybe_unused]] const auto value = ((NSNumber*)call.arguments[@"value"]).boolValue; +#if TARGET_OS_OSX +#else + if (value) { + [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionMixWithOthers error:nil]; + } else { + [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil]; + } +#endif } else { result(FlutterMethodNotImplemented); } diff --git a/darwin/fvp.podspec b/darwin/fvp.podspec index 9545cb5..b2e86da 100644 --- a/darwin/fvp.podspec +++ b/darwin/fvp.podspec @@ -1,6 +1,7 @@ # # To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html. # Run `pod lib lint fvp.podspec` to validate before publishing. +# Run `flutter clean` and rebuild to sync podspec changes # Pod::Spec.new do |s| s.name = 'fvp' @@ -14,6 +15,7 @@ Flutter video player plugin. s.author = { 'Wang Bin' => 'wbsecg1@gmail.com' } s.compiler_flags = '-Wno-documentation', '-std=c++20' + s.frameworks = 'AVFoundation' s.osx.frameworks = 'FlutterMacOS' #s.osx.pod_target_xcconfig = { 'OTHER_LDFLAGS' => '-framework FlutterMacOS' } s.source = { :path => '.' } diff --git a/lib/src/video_player_mdk.dart b/lib/src/video_player_mdk.dart index f7d4e21..b7258b1 100644 --- a/lib/src/video_player_mdk.dart +++ b/lib/src/video_player_mdk.dart @@ -8,6 +8,7 @@ import 'package:flutter/widgets.dart'; // import 'package:flutter/services.dart'; import 'package:video_player_platform_interface/video_player_platform_interface.dart'; import 'package:logging/logging.dart'; +import 'fvp_platform_interface.dart'; import 'extensions.dart'; import '../mdk.dart' as mdk; @@ -339,7 +340,9 @@ class MdkVideoPlayerPlatform extends VideoPlayerPlatform { } @override - Future setMixWithOthers(bool mixWithOthers) async {} + Future setMixWithOthers(bool mixWithOthers) async { + FvpPlatform.instance.setMixWithOthers(mixWithOthers); + } // more apis for fvp controller bool isLive(int textureId) {