|
|
|
@ -6,11 +6,19 @@ import UIKit |
|
|
|
public class FloatingUiPlugin: NSObject, FlutterPlugin { |
|
|
|
private var pipContentViewArray: [PlayerView] = [] |
|
|
|
|
|
|
|
/** |
|
|
|
* 更新音频会话配置,保证 PiP 播放场景的音频行为符合预期 |
|
|
|
* - Parameters: 无 |
|
|
|
* - Returns: 无 |
|
|
|
* - Throws: 无(内部捕获并记录 setCategory/setActive 可能抛出的异常) |
|
|
|
*/ |
|
|
|
private static func updateAudioSession() { |
|
|
|
let audioSession = AVAudioSession.sharedInstance() |
|
|
|
do { |
|
|
|
if #available(iOS 14.5, *) { |
|
|
|
try audioSession.setCategory(.playback, mode: .moviePlayback, options: [.overrideMutedMicrophoneInterruption]) |
|
|
|
try audioSession.setCategory(.playback, mode: .moviePlayback, options: [.overrideMutedMicrophoneInterruption, .mixWithOthers]) |
|
|
|
} else { |
|
|
|
try audioSession.setCategory(.playback, mode: .moviePlayback, options: [.mixWithOthers]) |
|
|
|
} |
|
|
|
try audioSession.setActive(true) |
|
|
|
} catch { |
|
|
|
@ -18,10 +26,14 @@ public class FloatingUiPlugin: NSObject, FlutterPlugin { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Flutter 插件注册入口 |
|
|
|
* - Parameters: |
|
|
|
* - registrar: FlutterPluginRegistrar 实例,用于注册通道与原生视图 |
|
|
|
* - Returns: 无 |
|
|
|
* - Throws: 无(注册流程不抛出异常) |
|
|
|
*/ |
|
|
|
public static func register(with registrar: FlutterPluginRegistrar) { |
|
|
|
// 保证 PiP 能正常工作 |
|
|
|
Self.updateAudioSession() |
|
|
|
|
|
|
|
let channel = FlutterMethodChannel(name: "native_plugin", binaryMessenger: registrar.messenger()) |
|
|
|
let instance = FloatingUiPlugin() |
|
|
|
registrar.addMethodCallDelegate(instance, channel: channel) |
|
|
|
@ -30,12 +42,21 @@ public class FloatingUiPlugin: NSObject, FlutterPlugin { |
|
|
|
registrar.register(factory, withId: "native_view") |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Flutter MethodChannel 调用处理入口 |
|
|
|
* - Parameters: |
|
|
|
* - call: Flutter 发起的方法调用(方法名与参数) |
|
|
|
* - result: 用于向 Flutter 回传结果的回调 |
|
|
|
* - Returns: 无 |
|
|
|
* - Throws: 无(内部逻辑不抛出异常,异常通过 result 或日志处理) |
|
|
|
*/ |
|
|
|
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) { |
|
|
|
switch call.method { |
|
|
|
case "getPlatformVersion": |
|
|
|
result("iOS " + UIDevice.current.systemVersion) |
|
|
|
|
|
|
|
case "createPipContentView": |
|
|
|
Self.updateAudioSession() |
|
|
|
let playerView = PlayerView() |
|
|
|
// 这里未来可以根据 PiP 的事件来控制播放状态 |
|
|
|
playerView.play() |
|
|
|
|