Skip to content

Commit

Permalink
Merge branch 'main' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
orz12 committed Jan 3, 2025
2 parents fb94624 + adbeaa7 commit a29094c
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 38 deletions.
112 changes: 100 additions & 12 deletions lib/plugin/pl_player/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ class PlPlayerController {
final RxList<Map<String, String>> _vttSubtitles = <Map<String, String>>[].obs;
final RxInt _vttSubtitlesIndex = 0.obs;

final RxDouble subtitleFontSize = 60.0.obs;
final RxDouble subtitleBottomPadding = 24.0.obs;

late Rx<TextStyle> subtitleStyle;

Timer? _timer;
Timer? _timerForSeek;
Timer? _timerForVolume;
Expand Down Expand Up @@ -410,6 +415,21 @@ class PlPlayerController {
setting.get(SettingBoxKey.enableLongShowControl, defaultValue: false);
horizontalScreen =
setting.get(SettingBoxKey.horizontalScreen, defaultValue: false);
subtitleFontSize.value = videoStorage
.get(VideoBoxKey.subtitleFontSize, defaultValue: 60.0)
.toDouble();
subtitleStyle = TextStyle(
height: 1.3,
fontSize: subtitleFontSize.value,
letterSpacing: 0.1,
wordSpacing: 0.1,
color: const Color(0xffffffff),
fontWeight: FontWeight.normal,
backgroundColor: const Color(0xaa000000),
).obs;
subtitleBottomPadding.value = videoStorage
.get(VideoBoxKey.subtitleBottomPadding, defaultValue: 24.0)
.toDouble();

List<double> defaultList = <double>[0.5, 0.75, 1.25, 1.5, 1.75, 3.0];
speedsList = List<double>.from(videoStorage
Expand Down Expand Up @@ -1298,16 +1318,6 @@ class PlPlayerController {
);
}

const TextStyle subTitleStyle = TextStyle(
height: 1.3,
fontSize: 60.0,
letterSpacing: 0.1,
wordSpacing: 0.1,
color: Color(0xffffffff),
fontWeight: FontWeight.normal,
backgroundColor: Color(0xaa000000),
);

print("enterPip");
print(videoIntroController);
print(bangumiIntroController);
Expand Down Expand Up @@ -1359,8 +1369,10 @@ class PlPlayerController {
!_continuePlayInBackground.value,
resumeUponEnteringForegroundMode: true,
// 字幕尺寸调节
subtitleViewConfiguration: const SubtitleViewConfiguration(
style: subTitleStyle, padding: EdgeInsets.all(24.0)),
subtitleViewConfiguration: SubtitleViewConfiguration(
style: subtitleStyle.value,
padding:
EdgeInsets.only(bottom: subtitleBottomPadding.value)),
fit: BoxFit.contain,
),
),
Expand Down Expand Up @@ -1671,4 +1683,80 @@ class PlPlayerController {
videoPlayerController?.setVideoTrack(
_onlyPlayAudio.value ? VideoTrack.no() : VideoTrack.auto());
}

void setSubtitleFontSize() {
showDialog(
context: Get.context!,
builder: (context) {
return AlertDialog(
title: const Text('字幕字号设置'),
content: StatefulBuilder(builder: (context, StateSetter setState) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
Slider(
value: subtitleFontSize.value,
onChanged: (double value) {
setState(() {
subtitleFontSize.value = value;
subtitleStyle.value = subtitleStyle.value
.copyWith(fontSize: subtitleFontSize.value);
});
},
onChangeEnd: (double value) {
videoStorage.put(VideoBoxKey.subtitleFontSize, value);
},
min: 40.0,
max: 120.0,
divisions: 80,
label: subtitleFontSize.value.round().toString(),
),
Text(
'当前字号:${subtitleFontSize.value.round()}',
style: const TextStyle(fontSize: 16),
),
],
);
}),
);
},
);
}

void setSubtitleBottomPadding() {
showDialog(
context: Get.context!,
builder: (context) {
return AlertDialog(
title: const Text('字幕底部间距设置'),
content: StatefulBuilder(builder: (context, StateSetter setState) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
Slider(
value: subtitleBottomPadding.value,
onChanged: (double value) {
setState(() {
subtitleBottomPadding.value = value;
});
},
onChangeEnd: (double value) {
videoStorage.put(VideoBoxKey.subtitleBottomPadding, value);
},
min: 10.0,
max: 180.0,
divisions: 170,
label: subtitleBottomPadding.value.round().toString(),
),
Text(
'当前底部间距:${subtitleBottomPadding.value.round()}',
style: const TextStyle(fontSize: 16),
),
],
);
}),
);
},
);
}
}
5 changes: 4 additions & 1 deletion lib/plugin/pl_player/models/player_gesture_action.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ enum PlayerGestureAction {
pipInside,
pipOutside,
backToHome,
prevPlay,
nextPlay,
}

extension PlayerGestureActionDesc on PlayerGestureAction {
String get description => ['无', '进入/退出全屏', '应用内小窗', '应用外小窗', '返回主页'][index];
String get description =>
['无', '进入/退出全屏', '应用内小窗', '应用外小窗', '返回主页', '播放上一集', '播放下一集'][index];
}

extension PlayerGestureActionCode on PlayerGestureAction {
Expand Down
72 changes: 48 additions & 24 deletions lib/plugin/pl_player/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -479,30 +479,49 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
height: 38,
child: PopupMenuButton<int>(
onSelected: (int value) {
_.setSubtitle(value);
switch (value) {
case -1:
_.setSubtitleFontSize();
break;
case -2:
_.setSubtitleBottomPadding();
break;
default:
_.setSubtitle(value);
}
},
initialValue:
_.vttSubtitles.length < _.vttSubtitlesIndex.value
? 0
: _.vttSubtitlesIndex.value,
color: Colors.black.withOpacity(0.8),
itemBuilder: (BuildContext context) {
return _.vttSubtitles.asMap().entries.map((entry) {
return PopupMenuItem<int>(
value: entry.key,
child: Text(
"${entry.value['title']}",
style: const TextStyle(color: Colors.white),
),
);
}).toList();
return [
const PopupMenuItem<int>(
value: -1,
child: Text("设置字号",
style: TextStyle(color: Colors.white))),
const PopupMenuItem<int>(
value: -2,
child: Text("设置底边距",
style: TextStyle(color: Colors.white))),
] +
_.vttSubtitles.asMap().entries.map((entry) {
return PopupMenuItem<int>(
value: entry.key,
child: Text("${entry.value['title']}",
style: const TextStyle(color: Colors.white)));
}).toList();
},
child: Container(
width: 42,
height: 38,
alignment: Alignment.center,
child: const Icon(
Icons.closed_caption,
child: Icon(
(_.vttSubtitlesIndex.value == 0 ||
_.vttSubtitles.length < _.vttSubtitlesIndex.value)
? Icons.closed_caption_off
: Icons.closed_caption,
size: 25,
color: Colors.white,
semanticLabel: '字幕',
Expand Down Expand Up @@ -589,28 +608,21 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
Widget build(BuildContext context) {
final PlPlayerController _ = widget.controller;
final Color colorTheme = Theme.of(context).colorScheme.primary;
const TextStyle subTitleStyle = TextStyle(
height: 1.3,
fontSize: 60.0,
letterSpacing: 0.1,
wordSpacing: 0.1,
color: Color(0xffffffff),
fontWeight: FontWeight.normal,
backgroundColor: Color(0xaa000000),
);
const TextStyle textStyle = TextStyle(
color: Colors.white,
fontSize: 12,
);
Widget video = Video(
key: ValueKey('${_.videoFit.value}${_.continuePlayInBackground.value}'),
key: ValueKey('${_.videoFit.value}${_.continuePlayInBackground.value}'
'${_.subtitleFontSize.value}${_.subtitleBottomPadding.value}'),
controller: videoController,
controls: NoVideoControls,
pauseUponEnteringBackgroundMode: !_.continuePlayInBackground.value,
resumeUponEnteringForegroundMode: true,
// 字幕尺寸调节
subtitleViewConfiguration: const SubtitleViewConfiguration(
style: subTitleStyle, padding: EdgeInsets.all(24.0)),
subtitleViewConfiguration: SubtitleViewConfiguration(
style: _.subtitleStyle.value,
padding: EdgeInsets.only(bottom: _.subtitleBottomPadding.value)),
fit: _.videoFit.value,
);
return Stack(
Expand Down Expand Up @@ -767,6 +779,18 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
Get.until((route) => route.isFirst);
popRouteStackContinuously = "";
break;
case PlayerGestureAction.prevPlay:
bool? ret;
ret ??= videoIntroController?.prevPlay();
ret ??= bangumiIntroController?.prevPlay();
SmartDialog.showToast(ret == true ? '上一集' : '没有上一集了');
break;
case PlayerGestureAction.nextPlay:
bool? ret;
ret ??= videoIntroController?.nextPlay();
ret ??= bangumiIntroController?.nextPlay();
SmartDialog.showToast(ret == true ? '下一集' : '没有下一集了');
break;
}
});
}
Expand Down
6 changes: 5 additions & 1 deletion lib/utils/storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,11 @@ class VideoBoxKey {
// 自定义倍速集合
customSpeedsList = 'customSpeedsList',
// 画面填充比例
cacheVideoFit = 'cacheVideoFit';
cacheVideoFit = 'cacheVideoFit',
// 字幕字体大小
subtitleFontSize = 'subtitleFontSize',
// 字幕距底边距
subtitleBottomPadding = 'subtitleBottomPadding';
}

class OnlineCacheKey {
Expand Down

0 comments on commit a29094c

Please sign in to comment.