提交 cbef6e07 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
上级 7cbb67fb
......@@ -83,9 +83,13 @@ static const int CODE_ON_RECEIVE_FIRST_FRAME = 2003;
- (void)onApplicationTerminateClick {
_isTerminate = YES;
_textureRegistry = nil;
[self stopPlay];
if (nil != _txVodPlayer) {
[_txVodPlayer removeVideoWidget];
_txVodPlayer = nil;
_txVodPlayer.videoProcessDelegate = nil;
}
_textureId = -1;
}
......@@ -93,6 +97,12 @@ static const int CODE_ON_RECEIVE_FIRST_FRAME = 2003;
_isTerminate = YES;
_textureRegistry = nil;
[self stopPlay];
if (nil != _txVodPlayer) {
[_txVodPlayer removeVideoWidget];
_txVodPlayer = nil;
_txVodPlayer.videoProcessDelegate = nil;
}
_textureId = -1;
}
- (void)destory
......@@ -472,13 +482,16 @@ static const int CODE_ON_RECEIVE_FIRST_FRAME = 2003;
CVPixelBufferRef old = _latestPixelBuffer;
while (!OSAtomicCompareAndSwapPtrBarrier(old, newBuffer,
(void **)&_latestPixelBuffer)) {
if (_isTerminate) {
break;
}
old = _latestPixelBuffer;
}
if (old && old != pixelBuffer) {
CFRelease(old);
}
if (!_isStoped && _textureRegistry && _textureId >= 0) {
if (!_isTerminate && !_isStoped && _textureRegistry && _textureId >= 0) {
[_textureRegistry textureFrameAvailable:_textureId];
}
}
......
......@@ -78,15 +78,17 @@ class TXLivePlayerController extends ChangeNotifier implements ValueListenable<T
break;
case TXVodPlayEvent.PLAY_EVT_CHANGE_RESOLUTION: //下行视频分辨率改变
if (defaultTargetPlatform == TargetPlatform.android) {
double? videoWidth = (event["videoWidth"]);
double? videoHeight = (event["videoHeight"]);
int? videoWidth = event[TXVodPlayEvent.EVT_VIDEO_WIDTH];
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)) {
resizeVideoWidth = videoWidth;
resizeVideoHeight = videoHeight;
videoLeft = event["videoLeft"];
videoTop = event["videoTop"];
videoRight = event["videoRight"];
videoBottom = event["videoBottom"];
resizeVideoWidth = videoWidth.toDouble();
resizeVideoHeight = videoHeight.toDouble();
videoLeft = event["videoLeft"] ?? 0;
videoTop = event["videoTop"] ?? 0;
videoRight = event["videoRight"] ?? 0;
videoBottom = event["videoBottom"] ?? 0;
}
}
break;
......
......@@ -87,15 +87,17 @@ class TXVodPlayerController extends ChangeNotifier implements ValueListenable<TX
break;
case TXVodPlayEvent.PLAY_EVT_CHANGE_RESOLUTION: // Downstream video resolution change.
if (defaultTargetPlatform == TargetPlatform.android) {
double? videoWidth = (event["videoWidth"]);
double? videoHeight = (event["videoHeight"]);
int? videoWidth = event[TXVodPlayEvent.EVT_VIDEO_WIDTH];
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)) {
resizeVideoWidth = videoWidth;
resizeVideoHeight = videoHeight;
videoLeft = event["videoLeft"];
videoTop = event["videoTop"];
videoRight = event["videoRight"];
videoBottom = event["videoBottom"];
resizeVideoWidth = videoWidth.toDouble();
resizeVideoHeight = videoHeight.toDouble();
videoLeft = event["videoLeft"] ?? 0;
videoTop = event["videoTop"] ?? 0;
videoRight = event["videoRight"] ?? 0;
videoBottom = event["videoBottom"] ?? 0;
}
}
int videoDegree = map['EVT_KEY_VIDEO_ROTATION'] ?? 0;
......
......@@ -51,4 +51,10 @@ class SuperPlayerUIStatus {
static const PIP_MODE = 2;
}
/// super player render mode
enum SuperPlayerRenderMode {
FILL_VIEW,
ADJUST_RESOLUTION
}
......@@ -8,8 +8,9 @@ FullScreenController _fullScreenController = FullScreenController();
/// superPlayer view widget
class SuperPlayerView extends StatefulWidget {
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
State<StatefulWidget> createState() => SuperPlayerViewState();
......@@ -80,8 +81,7 @@ class SuperPlayerViewState extends State<SuperPlayerView> with WidgetsBindingObs
EasyLoading.showToast(FSPLocal.current.txSpwStartDownload);
}
});
_bottomViewController =
BottomViewController(_onTapPlayControl, _onControlFullScreen, _onControlQualityListView, (value) {
_bottomViewController = BottomViewController(_onTapPlayControl, _onControlFullScreen, _onControlQualityListView, (value) {
_taskExecutors.addTask(() => _controlTest(true, value));
}, () {
_taskExecutors.addTask(() => _controlTest(false, 0));
......@@ -208,7 +208,7 @@ class SuperPlayerViewState extends State<SuperPlayerView> with WidgetsBindingObs
}, (info, list) {
// onVideoImageSpriteAndKeyFrameChanged
_videoBottomKey.currentState?.setKeyFrame(list);
},(){
}, () {
// onResolutionChanged
_calculateSize(_playController.videoWidth, _playController.videoHeight);
}, () {
......@@ -315,8 +315,7 @@ class SuperPlayerViewState extends State<SuperPlayerView> with WidgetsBindingObs
checkBrightness();
// 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.
if (_playController._playerUIStatus == SuperPlayerUIStatus.FULLSCREEN_MODE &&
defaultTargetPlatform == TargetPlatform.iOS) {
if (_playController._playerUIStatus == SuperPlayerUIStatus.FULLSCREEN_MODE && defaultTargetPlatform == TargetPlatform.iOS) {
Orientation currentOrientation = MediaQuery.of(context).orientation;
bool isLandscape = currentOrientation == Orientation.landscape;
if (!isLandscape) {
......@@ -333,14 +332,13 @@ class SuperPlayerViewState extends State<SuperPlayerView> with WidgetsBindingObs
void checkBrightness() async {
double? sysBrightness = await SuperPlayerPlugin.getSysBrightness();
double? windowBrightness = await SuperPlayerPlugin.getBrightness();
if(sysBrightness != windowBrightness && null != sysBrightness) {
if (sysBrightness != windowBrightness && null != sysBrightness) {
SuperPlayerPlugin.setBrightness(sysBrightness);
}
}
void _calculateSize(double videoWidth, double videoHeight) {
if (mounted && (0 != videoWidth && 0 != videoHeight) &&
(_videoWidth != videoWidth || _videoHeight != videoHeight)) {
if (mounted && (0 != videoWidth && 0 != videoHeight) && (_videoWidth != videoWidth || _videoHeight != videoHeight)) {
_videoWidth = videoWidth;
_videoHeight = videoHeight;
_resizeVideo();
......@@ -390,8 +388,16 @@ class SuperPlayerViewState extends State<SuperPlayerView> with WidgetsBindingObs
@override
Widget build(BuildContext context) {
return Center(
child: IntrinsicHeight(
child: Stack(
child: widget.renderMode == SuperPlayerRenderMode.ADJUST_RESOLUTION ?
IntrinsicHeight(
child: _getWidgetBody(),
)
: _getWidgetBody()
);
}
Widget _getWidgetBody() {
return Stack(
children: [
_getPlayer(),
_getTitleArea(),
......@@ -404,8 +410,7 @@ class SuperPlayerViewState extends State<SuperPlayerView> with WidgetsBindingObs
_getMoreMenuView(),
_getLoading(),
],
),
));
);
}
Widget _getImageSpriteView() {
......@@ -449,8 +454,8 @@ class SuperPlayerViewState extends State<SuperPlayerView> with WidgetsBindingObs
Widget _getQualityListView() {
return Visibility(
visible: _isShowQualityListView,
child: QualityListView(_qualitListViewController, _playController.currentQualityList,
_playController.currentQuality, _qualityListKey),
child:
QualityListView(_qualitListViewController, _playController.currentQualityList, _playController.currentQuality, _qualityListKey),
);
}
......@@ -503,10 +508,14 @@ class SuperPlayerViewState extends State<SuperPlayerView> with WidgetsBindingObs
highlightColor: Colors.transparent,
splashColor: Colors.transparent,
child: Center(
child: AspectRatio(
child: widget.renderMode == SuperPlayerRenderMode.ADJUST_RESOLUTION ?
AspectRatio(
aspectRatio: _aspectRatio,
child: TXPlayerVideo(controller: _playController.getCurrentController(), playerStream: _playController.getPlayerStream()))
: SizedBox(
child: TXPlayerVideo(
controller: _playController.getCurrentController(), playerStream: _playController.getPlayerStream())),
controller: _playController.getCurrentController(), playerStream: _playController.getPlayerStream()),
)
),
);
}
......@@ -518,13 +527,8 @@ class SuperPlayerViewState extends State<SuperPlayerView> with WidgetsBindingObs
top: topBottomOffset,
left: 0,
right: 0,
child: _VideoTitleView(
_titleViewController,
_playController._playerUIStatus == SuperPlayerUIStatus.FULLSCREEN_MODE,
_playController._getPlayName(),
_isShowDownload,
_isDownloaded,
_videoTitleKey),
child: _VideoTitleView(_titleViewController, _playController._playerUIStatus == SuperPlayerUIStatus.FULLSCREEN_MODE,
_playController._getPlayName(), _isShowDownload, _isDownloaded, _videoTitleKey),
),
);
}
......@@ -803,14 +807,12 @@ class FullScreenController {
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: SystemUiOverlay.values);
} else if (orientationDirection == TXVodPlayEvent.ORIENTATION_LANDSCAPE_RIGHT) {
SystemChrome.setPreferredOrientations(
Platform.isIOS ? [DeviceOrientation.landscapeRight] : [DeviceOrientation.landscapeLeft]);
SystemChrome.setPreferredOrientations(Platform.isIOS ? [DeviceOrientation.landscapeRight] : [DeviceOrientation.landscapeLeft]);
SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersive);
enterFullScreen();
} else if (orientationDirection == TXVodPlayEvent.ORIENTATION_PORTRAIT_DOWN) {
} else if (orientationDirection == TXVodPlayEvent.ORIENTATION_LANDSCAPE_LEFT) {
SystemChrome.setPreferredOrientations(
Platform.isIOS ? [DeviceOrientation.landscapeLeft] : [DeviceOrientation.landscapeRight]);
SystemChrome.setPreferredOrientations(Platform.isIOS ? [DeviceOrientation.landscapeLeft] : [DeviceOrientation.landscapeRight]);
SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersive);
enterFullScreen();
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论