提交 59567c0d authored 作者: kongdywang's avatar kongdywang

1. superPlayerWidget has added ability to config video render mode

2. prevent app ios crash when kill 3. fix issue that vod player can not pick width
上级 36365290
...@@ -83,9 +83,13 @@ static const int CODE_ON_RECEIVE_FIRST_FRAME = 2003; ...@@ -83,9 +83,13 @@ static const int CODE_ON_RECEIVE_FIRST_FRAME = 2003;
- (void)onApplicationTerminateClick { - (void)onApplicationTerminateClick {
_isTerminate = YES; _isTerminate = YES;
_textureRegistry = nil;
[self stopPlay];
if (nil != _txVodPlayer) {
[_txVodPlayer removeVideoWidget]; [_txVodPlayer removeVideoWidget];
_txVodPlayer = nil; _txVodPlayer = nil;
_txVodPlayer.videoProcessDelegate = nil; _txVodPlayer.videoProcessDelegate = nil;
}
_textureId = -1; _textureId = -1;
} }
...@@ -93,6 +97,12 @@ static const int CODE_ON_RECEIVE_FIRST_FRAME = 2003; ...@@ -93,6 +97,12 @@ static const int CODE_ON_RECEIVE_FIRST_FRAME = 2003;
_isTerminate = YES; _isTerminate = YES;
_textureRegistry = nil; _textureRegistry = nil;
[self stopPlay]; [self stopPlay];
if (nil != _txVodPlayer) {
[_txVodPlayer removeVideoWidget];
_txVodPlayer = nil;
_txVodPlayer.videoProcessDelegate = nil;
}
_textureId = -1;
} }
- (void)destory - (void)destory
...@@ -472,13 +482,16 @@ static const int CODE_ON_RECEIVE_FIRST_FRAME = 2003; ...@@ -472,13 +482,16 @@ static const int CODE_ON_RECEIVE_FIRST_FRAME = 2003;
CVPixelBufferRef old = _latestPixelBuffer; CVPixelBufferRef old = _latestPixelBuffer;
while (!OSAtomicCompareAndSwapPtrBarrier(old, newBuffer, while (!OSAtomicCompareAndSwapPtrBarrier(old, newBuffer,
(void **)&_latestPixelBuffer)) { (void **)&_latestPixelBuffer)) {
if (_isTerminate) {
break;
}
old = _latestPixelBuffer; old = _latestPixelBuffer;
} }
if (old && old != pixelBuffer) { if (old && old != pixelBuffer) {
CFRelease(old); CFRelease(old);
} }
if (!_isStoped && _textureRegistry && _textureId >= 0) { if (!_isTerminate && !_isStoped && _textureRegistry && _textureId >= 0) {
[_textureRegistry textureFrameAvailable:_textureId]; [_textureRegistry textureFrameAvailable:_textureId];
} }
} }
......
...@@ -78,15 +78,17 @@ class TXLivePlayerController extends ChangeNotifier implements ValueListenable<T ...@@ -78,15 +78,17 @@ class TXLivePlayerController extends ChangeNotifier implements ValueListenable<T
break; break;
case TXVodPlayEvent.PLAY_EVT_CHANGE_RESOLUTION: //下行视频分辨率改变 case TXVodPlayEvent.PLAY_EVT_CHANGE_RESOLUTION: //下行视频分辨率改变
if (defaultTargetPlatform == TargetPlatform.android) { if (defaultTargetPlatform == TargetPlatform.android) {
double? videoWidth = (event["videoWidth"]); int? videoWidth = event[TXVodPlayEvent.EVT_VIDEO_WIDTH];
double? videoHeight = (event["videoHeight"]); int? videoHeight = event[TXVodPlayEvent.EVT_VIDEO_HEIGHT];
videoWidth ??= event[TXVodPlayEvent.EVT_PARAM1];
videoHeight ??= event[TXVodPlayEvent.EVT_PARAM2];
if ((videoWidth != null && videoWidth > 0) && (videoHeight != null && videoHeight > 0)) { if ((videoWidth != null && videoWidth > 0) && (videoHeight != null && videoHeight > 0)) {
resizeVideoWidth = videoWidth; resizeVideoWidth = videoWidth.toDouble();
resizeVideoHeight = videoHeight; resizeVideoHeight = videoHeight.toDouble();
videoLeft = event["videoLeft"]; videoLeft = event["videoLeft"] ?? 0;
videoTop = event["videoTop"]; videoTop = event["videoTop"] ?? 0;
videoRight = event["videoRight"]; videoRight = event["videoRight"] ?? 0;
videoBottom = event["videoBottom"]; videoBottom = event["videoBottom"] ?? 0;
} }
} }
break; break;
......
...@@ -87,15 +87,17 @@ class TXVodPlayerController extends ChangeNotifier implements ValueListenable<TX ...@@ -87,15 +87,17 @@ class TXVodPlayerController extends ChangeNotifier implements ValueListenable<TX
break; break;
case TXVodPlayEvent.PLAY_EVT_CHANGE_RESOLUTION: // Downstream video resolution change. case TXVodPlayEvent.PLAY_EVT_CHANGE_RESOLUTION: // Downstream video resolution change.
if (defaultTargetPlatform == TargetPlatform.android) { if (defaultTargetPlatform == TargetPlatform.android) {
double? videoWidth = (event["videoWidth"]); int? videoWidth = event[TXVodPlayEvent.EVT_VIDEO_WIDTH];
double? videoHeight = (event["videoHeight"]); int? videoHeight = event[TXVodPlayEvent.EVT_VIDEO_HEIGHT];
videoWidth ??= event[TXVodPlayEvent.EVT_PARAM1];
videoHeight ??= event[TXVodPlayEvent.EVT_PARAM2];
if ((videoWidth != null && videoWidth > 0) && (videoHeight != null && videoHeight > 0)) { if ((videoWidth != null && videoWidth > 0) && (videoHeight != null && videoHeight > 0)) {
resizeVideoWidth = videoWidth; resizeVideoWidth = videoWidth.toDouble();
resizeVideoHeight = videoHeight; resizeVideoHeight = videoHeight.toDouble();
videoLeft = event["videoLeft"]; videoLeft = event["videoLeft"] ?? 0;
videoTop = event["videoTop"]; videoTop = event["videoTop"] ?? 0;
videoRight = event["videoRight"]; videoRight = event["videoRight"] ?? 0;
videoBottom = event["videoBottom"]; videoBottom = event["videoBottom"] ?? 0;
} }
} }
int videoDegree = map['EVT_KEY_VIDEO_ROTATION'] ?? 0; int videoDegree = map['EVT_KEY_VIDEO_ROTATION'] ?? 0;
......
...@@ -51,4 +51,10 @@ class SuperPlayerUIStatus { ...@@ -51,4 +51,10 @@ class SuperPlayerUIStatus {
static const PIP_MODE = 2; static const PIP_MODE = 2;
} }
/// super player render mode
enum SuperPlayerRenderMode {
FILL_VIEW,
ADJUST_RESOLUTION
}
...@@ -8,8 +8,9 @@ FullScreenController _fullScreenController = FullScreenController(); ...@@ -8,8 +8,9 @@ FullScreenController _fullScreenController = FullScreenController();
/// superPlayer view widget /// superPlayer view widget
class SuperPlayerView extends StatefulWidget { class SuperPlayerView extends StatefulWidget {
final SuperPlayerController _controller; final SuperPlayerController _controller;
final SuperPlayerRenderMode renderMode;
const SuperPlayerView(this._controller, {Key? viewKey}) : super(key: viewKey); SuperPlayerView(this._controller, {Key? viewKey, this.renderMode = SuperPlayerRenderMode.ADJUST_RESOLUTION}) : super(key: viewKey);
@override @override
State<StatefulWidget> createState() => SuperPlayerViewState(); State<StatefulWidget> createState() => SuperPlayerViewState();
...@@ -80,8 +81,7 @@ class SuperPlayerViewState extends State<SuperPlayerView> with WidgetsBindingObs ...@@ -80,8 +81,7 @@ class SuperPlayerViewState extends State<SuperPlayerView> with WidgetsBindingObs
EasyLoading.showToast(FSPLocal.current.txSpwStartDownload); EasyLoading.showToast(FSPLocal.current.txSpwStartDownload);
} }
}); });
_bottomViewController = _bottomViewController = BottomViewController(_onTapPlayControl, _onControlFullScreen, _onControlQualityListView, (value) {
BottomViewController(_onTapPlayControl, _onControlFullScreen, _onControlQualityListView, (value) {
_taskExecutors.addTask(() => _controlTest(true, value)); _taskExecutors.addTask(() => _controlTest(true, value));
}, () { }, () {
_taskExecutors.addTask(() => _controlTest(false, 0)); _taskExecutors.addTask(() => _controlTest(false, 0));
...@@ -210,7 +210,7 @@ class SuperPlayerViewState extends State<SuperPlayerView> with WidgetsBindingObs ...@@ -210,7 +210,7 @@ class SuperPlayerViewState extends State<SuperPlayerView> with WidgetsBindingObs
}, (info, list) { }, (info, list) {
// onVideoImageSpriteAndKeyFrameChanged // onVideoImageSpriteAndKeyFrameChanged
_videoBottomKey.currentState?.setKeyFrame(list); _videoBottomKey.currentState?.setKeyFrame(list);
},(){ }, () {
// onResolutionChanged // onResolutionChanged
_calculateSize(_playController.videoWidth, _playController.videoHeight); _calculateSize(_playController.videoWidth, _playController.videoHeight);
}, () { }, () {
...@@ -317,8 +317,7 @@ class SuperPlayerViewState extends State<SuperPlayerView> with WidgetsBindingObs ...@@ -317,8 +317,7 @@ class SuperPlayerViewState extends State<SuperPlayerView> with WidgetsBindingObs
checkBrightness(); checkBrightness();
// If the screen orientation is changed from landscape to portrait after returning from the background, // If the screen orientation is changed from landscape to portrait after returning from the background,
// switch to landscape mode based on the judgment made here. // switch to landscape mode based on the judgment made here.
if (_playController._playerUIStatus == SuperPlayerUIStatus.FULLSCREEN_MODE && if (_playController._playerUIStatus == SuperPlayerUIStatus.FULLSCREEN_MODE && defaultTargetPlatform == TargetPlatform.iOS) {
defaultTargetPlatform == TargetPlatform.iOS) {
Orientation currentOrientation = MediaQuery.of(context).orientation; Orientation currentOrientation = MediaQuery.of(context).orientation;
bool isLandscape = currentOrientation == Orientation.landscape; bool isLandscape = currentOrientation == Orientation.landscape;
if (!isLandscape) { if (!isLandscape) {
...@@ -335,14 +334,13 @@ class SuperPlayerViewState extends State<SuperPlayerView> with WidgetsBindingObs ...@@ -335,14 +334,13 @@ class SuperPlayerViewState extends State<SuperPlayerView> with WidgetsBindingObs
void checkBrightness() async { void checkBrightness() async {
double? sysBrightness = await SuperPlayerPlugin.getSysBrightness(); double? sysBrightness = await SuperPlayerPlugin.getSysBrightness();
double? windowBrightness = await SuperPlayerPlugin.getBrightness(); double? windowBrightness = await SuperPlayerPlugin.getBrightness();
if(sysBrightness != windowBrightness && null != sysBrightness) { if (sysBrightness != windowBrightness && null != sysBrightness) {
SuperPlayerPlugin.setBrightness(sysBrightness); SuperPlayerPlugin.setBrightness(sysBrightness);
} }
} }
void _calculateSize(double videoWidth, double videoHeight) { void _calculateSize(double videoWidth, double videoHeight) {
if (mounted && (0 != videoWidth && 0 != videoHeight) && if (mounted && (0 != videoWidth && 0 != videoHeight) && (_videoWidth != videoWidth || _videoHeight != videoHeight)) {
(_videoWidth != videoWidth || _videoHeight != videoHeight)) {
_videoWidth = videoWidth; _videoWidth = videoWidth;
_videoHeight = videoHeight; _videoHeight = videoHeight;
_resizeVideo(); _resizeVideo();
...@@ -392,8 +390,16 @@ class SuperPlayerViewState extends State<SuperPlayerView> with WidgetsBindingObs ...@@ -392,8 +390,16 @@ class SuperPlayerViewState extends State<SuperPlayerView> with WidgetsBindingObs
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Center( return Center(
child: IntrinsicHeight( child: widget.renderMode == SuperPlayerRenderMode.ADJUST_RESOLUTION ?
child: Stack( IntrinsicHeight(
child: _getWidgetBody(),
)
: _getWidgetBody()
);
}
Widget _getWidgetBody() {
return Stack(
children: [ children: [
_getPlayer(), _getPlayer(),
_getTitleArea(), _getTitleArea(),
...@@ -406,8 +412,7 @@ class SuperPlayerViewState extends State<SuperPlayerView> with WidgetsBindingObs ...@@ -406,8 +412,7 @@ class SuperPlayerViewState extends State<SuperPlayerView> with WidgetsBindingObs
_getMoreMenuView(), _getMoreMenuView(),
_getLoading(), _getLoading(),
], ],
), );
));
} }
Widget _getImageSpriteView() { Widget _getImageSpriteView() {
...@@ -451,8 +456,8 @@ class SuperPlayerViewState extends State<SuperPlayerView> with WidgetsBindingObs ...@@ -451,8 +456,8 @@ class SuperPlayerViewState extends State<SuperPlayerView> with WidgetsBindingObs
Widget _getQualityListView() { Widget _getQualityListView() {
return Visibility( return Visibility(
visible: _isShowQualityListView, visible: _isShowQualityListView,
child: QualityListView(_qualitListViewController, _playController.currentQualityList, child:
_playController.currentQuality, _qualityListKey), QualityListView(_qualitListViewController, _playController.currentQualityList, _playController.currentQuality, _qualityListKey),
); );
} }
...@@ -505,10 +510,14 @@ class SuperPlayerViewState extends State<SuperPlayerView> with WidgetsBindingObs ...@@ -505,10 +510,14 @@ class SuperPlayerViewState extends State<SuperPlayerView> with WidgetsBindingObs
highlightColor: Colors.transparent, highlightColor: Colors.transparent,
splashColor: Colors.transparent, splashColor: Colors.transparent,
child: Center( child: Center(
child: AspectRatio( child: widget.renderMode == SuperPlayerRenderMode.ADJUST_RESOLUTION ?
AspectRatio(
aspectRatio: _aspectRatio, aspectRatio: _aspectRatio,
child: TXPlayerVideo(controller: _playController.getCurrentController(), playerStream: _playController.getPlayerStream()))
: SizedBox(
child: TXPlayerVideo( child: TXPlayerVideo(
controller: _playController.getCurrentController(), playerStream: _playController.getPlayerStream())), controller: _playController.getCurrentController(), playerStream: _playController.getPlayerStream()),
)
), ),
); );
} }
...@@ -520,13 +529,8 @@ class SuperPlayerViewState extends State<SuperPlayerView> with WidgetsBindingObs ...@@ -520,13 +529,8 @@ class SuperPlayerViewState extends State<SuperPlayerView> with WidgetsBindingObs
top: topBottomOffset, top: topBottomOffset,
left: 0, left: 0,
right: 0, right: 0,
child: _VideoTitleView( child: _VideoTitleView(_titleViewController, _playController._playerUIStatus == SuperPlayerUIStatus.FULLSCREEN_MODE,
_titleViewController, _playController._getPlayName(), _isShowDownload, _isDownloaded, _videoTitleKey),
_playController._playerUIStatus == SuperPlayerUIStatus.FULLSCREEN_MODE,
_playController._getPlayName(),
_isShowDownload,
_isDownloaded,
_videoTitleKey),
), ),
); );
} }
...@@ -805,14 +809,12 @@ class FullScreenController { ...@@ -805,14 +809,12 @@ class FullScreenController {
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: SystemUiOverlay.values); SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: SystemUiOverlay.values);
} else if (orientationDirection == TXVodPlayEvent.ORIENTATION_LANDSCAPE_RIGHT) { } else if (orientationDirection == TXVodPlayEvent.ORIENTATION_LANDSCAPE_RIGHT) {
SystemChrome.setPreferredOrientations( SystemChrome.setPreferredOrientations(Platform.isIOS ? [DeviceOrientation.landscapeRight] : [DeviceOrientation.landscapeLeft]);
Platform.isIOS ? [DeviceOrientation.landscapeRight] : [DeviceOrientation.landscapeLeft]);
SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersive); SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersive);
enterFullScreen(); enterFullScreen();
} else if (orientationDirection == TXVodPlayEvent.ORIENTATION_PORTRAIT_DOWN) { } else if (orientationDirection == TXVodPlayEvent.ORIENTATION_PORTRAIT_DOWN) {
} else if (orientationDirection == TXVodPlayEvent.ORIENTATION_LANDSCAPE_LEFT) { } else if (orientationDirection == TXVodPlayEvent.ORIENTATION_LANDSCAPE_LEFT) {
SystemChrome.setPreferredOrientations( SystemChrome.setPreferredOrientations(Platform.isIOS ? [DeviceOrientation.landscapeLeft] : [DeviceOrientation.landscapeRight]);
Platform.isIOS ? [DeviceOrientation.landscapeLeft] : [DeviceOrientation.landscapeRight]);
SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersive); SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersive);
enterFullScreen(); enterFullScreen();
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论