提交 fdf58452 authored 作者: kongdywang's avatar kongdywang

1. fix player widget isn't throw event when switch video and release

2. player widget add stopPlay method 3. vod/live controller's method which named dispose can await now
上级 cbef6e07
...@@ -416,14 +416,18 @@ class _DemoSuperPlayerState extends State<DemoSuperPlayer> with TXPipPlayerResto ...@@ -416,14 +416,18 @@ class _DemoSuperPlayerState extends State<DemoSuperPlayer> with TXPipPlayerResto
@override @override
void dispose() { void dispose() {
_releasePlayerSource();
super.dispose();
}
Future<void> _releasePlayerSource() async {
// must invoke when page exit. // must invoke when page exit.
_controller.releasePlayer(); await _controller.releasePlayer();
simpleEventSubscription?.cancel();
// restore current brightness to sys brightness // restore current brightness to sys brightness
SuperPlayerPlugin.restorePageBrightness(); SuperPlayerPlugin.restorePageBrightness();
// unregister brightness observer // unregister brightness observer
SuperPlayerPlugin.registerSysBrightness(false); SuperPlayerPlugin.registerSysBrightness(false);
super.dispose(); simpleEventSubscription?.cancel();
} }
@override @override
......
...@@ -365,7 +365,7 @@ class TXLivePlayerController extends ChangeNotifier implements ValueListenable<T ...@@ -365,7 +365,7 @@ class TXLivePlayerController extends ChangeNotifier implements ValueListenable<T
/// ///
/// 释放controller /// 释放controller
@override @override
void dispose() async { Future<void> dispose() async {
_isNeedDisposed = true; _isNeedDisposed = true;
if (!_isDisposed) { if (!_isDisposed) {
await _eventSubscription!.cancel(); await _eventSubscription!.cancel();
......
...@@ -21,5 +21,5 @@ abstract class TXPlayerController { ...@@ -21,5 +21,5 @@ abstract class TXPlayerController {
Future<int> enterPictureInPictureMode( Future<int> enterPictureInPictureMode(
{String? backIconForAndroid, String? playIconForAndroid, String? pauseIconForAndroid, String? forwardIconForAndroid}); {String? backIconForAndroid, String? playIconForAndroid, String? pauseIconForAndroid, String? forwardIconForAndroid});
Future<void> exitPictureInPictureMode(); Future<void> exitPictureInPictureMode();
void dispose(); Future<void> dispose();
} }
\ No newline at end of file
...@@ -582,7 +582,7 @@ class TXVodPlayerController extends ChangeNotifier implements ValueListenable<TX ...@@ -582,7 +582,7 @@ class TXVodPlayerController extends ChangeNotifier implements ValueListenable<TX
/// ///
/// 释放controller /// 释放controller
@override @override
void dispose() async { Future<void> dispose() async {
_isNeedDisposed = true; _isNeedDisposed = true;
if (!_isDisposed) { if (!_isDisposed) {
await _eventSubscription!.cancel(); await _eventSubscription!.cancel();
......
...@@ -205,7 +205,7 @@ class SuperPlayerController { ...@@ -205,7 +205,7 @@ class SuperPlayerController {
break; break;
case TXVodPlayEvent.PLAY_ERR_NET_DISCONNECT: case TXVodPlayEvent.PLAY_ERR_NET_DISCONNECT:
case TXVodPlayEvent.PLAY_EVT_PLAY_END: case TXVodPlayEvent.PLAY_EVT_PLAY_END:
_stop(); stopPlay();
if (eventCode == TXVodPlayEvent.PLAY_ERR_NET_DISCONNECT) { if (eventCode == TXVodPlayEvent.PLAY_ERR_NET_DISCONNECT) {
_observer?.onError(SuperPlayerCode.NET_ERROR, FSPLocal.current.txSpwNetWeak); _observer?.onError(SuperPlayerCode.NET_ERROR, FSPLocal.current.txSpwNetWeak);
} else { } else {
...@@ -286,7 +286,7 @@ class SuperPlayerController { ...@@ -286,7 +286,7 @@ class SuperPlayerController {
Future<void> playWithModelNeedLicence(SuperPlayerModel videoModel) async { Future<void> playWithModelNeedLicence(SuperPlayerModel videoModel) async {
this.videoModel = videoModel; this.videoModel = videoModel;
_playAction = videoModel.playAction; _playAction = videoModel.playAction;
await resetPlayer(); await stopPlay();
if (_playAction == SuperPlayerModel.PLAY_ACTION_AUTO_PLAY || _playAction == SuperPlayerModel.PLAY_ACTION_PRELOAD) { if (_playAction == SuperPlayerModel.PLAY_ACTION_AUTO_PLAY || _playAction == SuperPlayerModel.PLAY_ACTION_PRELOAD) {
await _playWithModelInner(videoModel); await _playWithModelInner(videoModel);
} }
...@@ -669,23 +669,23 @@ class SuperPlayerController { ...@@ -669,23 +669,23 @@ class SuperPlayerController {
_updatePlayerState(SuperPlayerState.INIT); _updatePlayerState(SuperPlayerState.INIT);
} }
void _stop() async { Future<void> stopPlay() async {
resetPlayer();
_updatePlayerState(SuperPlayerState.END); _updatePlayerState(SuperPlayerState.END);
await resetPlayer();
} }
/// Release the player. Once the player is released, it cannot be used again /// Release the player. Once the player is released, it cannot be used again
/// 释放播放器,播放器释放之后,将不能再使用 /// 释放播放器,播放器释放之后,将不能再使用
Future<void> releasePlayer() async { Future<void> releasePlayer() async {
// Remove the event listener for the widget first.
_observer?.onDispose();
playerStreamController.close();
// If in picture-in-picture mode, the player should not be released temporarily. // If in picture-in-picture mode, the player should not be released temporarily.
if (!TXPipController.instance.isPlayerInPip(getCurrentController())) { if (!TXPipController.instance.isPlayerInPip(getCurrentController())) {
resetPlayer(); await stopPlay();
_vodPlayerController.dispose(); await _vodPlayerController.dispose();
_livePlayerController.dispose(); await _livePlayerController.dispose();
} }
// Remove the event listener for the widget.
_observer?.onDispose();
playerStreamController.close();
} }
/// return true: executed exit full screen and other operations, consumed the return event. return false: did not consume the event. /// return true: executed exit full screen and other operations, consumed the return event. return false: did not consume the event.
......
...@@ -164,8 +164,10 @@ class SuperPlayerViewState extends State<SuperPlayerView> with WidgetsBindingObs ...@@ -164,8 +164,10 @@ class SuperPlayerViewState extends State<SuperPlayerView> with WidgetsBindingObs
_togglePlayUIState(false); _togglePlayUIState(false);
}, () { }, () {
// onPlayStop // onPlayStop
if (mounted) {
showControlView(false); showControlView(false);
_togglePlayUIState(false); _togglePlayUIState(false);
}
}, () { }, () {
// onRcvFirstIframe // onRcvFirstIframe
_coverViewKey.currentState?.hideCover(); _coverViewKey.currentState?.hideCover();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论