Skip to content

Commit

Permalink
implement setMixWithOthers for iOS. #172
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Oct 28, 2024
1 parent f63ab8b commit 8f39ffe
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
19 changes: 15 additions & 4 deletions darwin/Classes/FvpPlugin.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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 <AVFoundation/AVFoundation.h>
#import <CoreVideo/CoreVideo.h>
#import <Metal/Metal.h>
#include <mutex>
#include <unordered_map>
#include <iostream>
Expand Down Expand Up @@ -149,8 +150,8 @@ - (instancetype)initWithRegistrar:(NSObject<FlutterPluginRegistrar>*)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<TexturePlayer>(handle, width, height, _texRegistry);
players[player->textureId()] = player;
result(@(player->textureId()));
Expand All @@ -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);
}
Expand Down
2 changes: 2 additions & 0 deletions darwin/fvp.podspec
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -14,6 +15,7 @@ Flutter video player plugin.
s.author = { 'Wang Bin' => '[email protected]' }

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 => '.' }
Expand Down
5 changes: 4 additions & 1 deletion lib/src/video_player_mdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -339,7 +340,9 @@ class MdkVideoPlayerPlatform extends VideoPlayerPlatform {
}

@override
Future<void> setMixWithOthers(bool mixWithOthers) async {}
Future<void> setMixWithOthers(bool mixWithOthers) async {
FvpPlatform.instance.setMixWithOthers(mixWithOthers);
}

// more apis for fvp controller
bool isLive(int textureId) {
Expand Down

0 comments on commit 8f39ffe

Please sign in to comment.