提交 0bb3bd20 authored 作者: zhiruiou's avatar zhiruiou

SuperPlayerView添加resetPlayer释放播放器,避免FlutterPlatformView内存泄露问题

上级 469d52b1
...@@ -159,7 +159,10 @@ public class SuperPlatformPlayerView implements PlatformView, MethodChannel.Meth ...@@ -159,7 +159,10 @@ public class SuperPlatformPlayerView implements PlatformView, MethodChannel.Meth
Boolean enable = call.argument("loop"); Boolean enable = call.argument("loop");
setLoop(enable); setLoop(enable);
result.success(null); result.success(null);
} else { } else if(call.method.equals("resetPlayer")){
destory();
result.success(null);
}else {
result.notImplemented(); result.notImplemented();
} }
} }
...@@ -265,4 +268,11 @@ public class SuperPlatformPlayerView implements PlatformView, MethodChannel.Meth ...@@ -265,4 +268,11 @@ public class SuperPlatformPlayerView implements PlatformView, MethodChannel.Meth
return param; return param;
} }
private void destory() {
mSuperPlayerView.resetPlayer();
mSuperPlayerView = null;
mMethodChannel.setMethodCallHandler(null);
mEventChannel.setStreamHandler(null);
}
} }
...@@ -44,6 +44,12 @@ class _TestSuperPlayerState extends State<TestSuperPlayer> { ...@@ -44,6 +44,12 @@ class _TestSuperPlayerState extends State<TestSuperPlayer> {
debugPrint("= initState = ${window.padding.top}, ${window.physicalSize.width}"); debugPrint("= initState = ${window.padding.top}, ${window.physicalSize.width}");
} }
@override
void dispose() {
_playerController.resetPlayer();
super.dispose();
}
void onPressed(BuildContext context) { void onPressed(BuildContext context) {
showDialog( showDialog(
context: context, context: context,
......
...@@ -102,9 +102,18 @@ ...@@ -102,9 +102,18 @@
} }
- (void)dealloc - (void)dealloc
{
[self destory];
}
- (void)destory
{ {
[_realPlayerView resetPlayer]; [_realPlayerView resetPlayer];
[_eventChannel setStreamHandler:nil];
_realPlayerView = nil;
_eventChannel = nil;
_methodChannel = nil;
_eventSink = nil;
} }
- (void)reloadView:(NSString *)url appId:(long)appId fileId:(NSString *)fileId psign:(NSString *)psign - (void)reloadView:(NSString *)url appId:(long)appId fileId:(NSString *)fileId psign:(NSString *)psign
...@@ -243,6 +252,9 @@ ...@@ -243,6 +252,9 @@
BOOL loop = [args[@"loop"] boolValue]; BOOL loop = [args[@"loop"] boolValue];
[self setLoop:loop]; [self setLoop:loop];
result(nil); result(nil);
}else if ([@"resetPlayer" isEqualToString:call.method]) {
[self destory];
result(nil);
}else { }else {
result(FlutterMethodNotImplemented); result(FlutterMethodNotImplemented);
} }
......
...@@ -58,4 +58,8 @@ class SuperPlayerPlatformViewController { ...@@ -58,4 +58,8 @@ class SuperPlayerPlatformViewController {
await _channel.invokeMethod("setLoop", {"loop": loop}); await _channel.invokeMethod("setLoop", {"loop": loop});
} }
Future<void> resetPlayer() async {
await _channel.invokeMethod("resetPlayer");
}
} }
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论