Signing & Capabilities
-> Capability
添加 BackgroundModes
勾选 Audio,AirPlay,And Picture in Picture
Signing & Capabilities
-> Capability
Add BackgroundModes
check Audio,AirPlay,And Picture in Picture
/ios/Runner/AppDelegate.swift
的内容/ios/Runner/AppDelegate.swift
import fl_pip
import Flutter
import UIKit
@main
@objc class AppDelegate: FlFlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
override func registerPlugin(_ registry: FlutterPluginRegistry) {
GeneratedPluginRegistrant.register(with: registry)
}
}
android/app/src/main/${your package name}/MainActivity
修改 MainActivity 继承,android/app/src/main/${your package name}/MainActivity
,
class MainActivity : FlPiPActivity()
class MainActivity extends FlPiPActivity {
}
android AndroidManifest file android/app/src/main/AndroidManifest.xml
,
add android:supportsPictureInPicture="true"
<application android:label="FlPiP">
<activity android:name=".MainActivity" android:launchMode="singleTop" android:supportsPictureInPicture="true" />
</application>
/// 开启画中画
/// Open picture-in-picture
void enable() {
FlPiP().enable(
iosConfig: FlPiPiOSConfig(),
androidConfig: FlPiPAndroidConfig(
aspectRatio: const Rational.maxLandscape()));
}
/// 是否支持画中画
/// Whether to support picture in picture
void isAvailable() {
FlPiP().isAvailable;
}
/// 画中画状态
/// Picture-in-picture window state
void isActive() {
FlPiP().isActive;
}
/// 切换前后台
/// Toggle front and back
/// ios仅支持切换后台
/// ios supports background switching only
void toggle() {
FlPiP().toggle();
}
/// 退出画中画
/// Quit painting in picture
void disable() {
FlPiP().disable();
}
/// mainName must be the same as the method name
@pragma('vm:entry-point')
void pipMain() {
runApp(YourApp());
}
https://github.com/user-attachments/assets/1ba2238e-e556-4f87-8ccb-1b25440a6649