opt: sponsor block

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2024-11-11 18:28:04 +08:00
parent 44f5484aed
commit e4aab44f71
3 changed files with 26 additions and 25 deletions

View File

@@ -46,7 +46,7 @@ class _PlDanmakuState extends State<PlDanmaku> with WidgetsBindingObserver {
showDanmaku = true; showDanmaku = true;
} else if (state == AppLifecycleState.paused) { } else if (state == AppLifecycleState.paused) {
showDanmaku = false; showDanmaku = false;
playerController.danmakuController?.clear(); _controller?.clear();
} }
} }
@@ -89,11 +89,10 @@ class _PlDanmakuState extends State<PlDanmaku> with WidgetsBindingObserver {
// 播放器状态监听 // 播放器状态监听
void playerListener(PlayerStatus? status) { void playerListener(PlayerStatus? status) {
if (status == PlayerStatus.paused) {
_controller?.pause();
}
if (status == PlayerStatus.playing) { if (status == PlayerStatus.playing) {
_controller?.onResume(); _controller?.onResume();
} else {
_controller?.pause();
} }
} }
@@ -112,7 +111,10 @@ class _PlDanmakuState extends State<PlDanmaku> with WidgetsBindingObserver {
List<DanmakuElem>? currentDanmakuList = List<DanmakuElem>? currentDanmakuList =
_plDanmakuController.getCurrentDanmaku(currentPosition); _plDanmakuController.getCurrentDanmaku(currentPosition);
if (showDanmaku && currentDanmakuList != null && _controller != null) { if (showDanmaku &&
playerController.playerStatus.status.value == PlayerStatus.playing &&
currentDanmakuList != null &&
_controller != null) {
Color? defaultColor = playerController.blockTypes.contains(6) Color? defaultColor = playerController.blockTypes.contains(6)
? DmUtils.decimalToColor(16777215) ? DmUtils.decimalToColor(16777215)
: null; : null;
@@ -132,6 +134,8 @@ class _PlDanmakuState extends State<PlDanmaku> with WidgetsBindingObserver {
void dispose() { void dispose() {
WidgetsBinding.instance.removeObserver(this); WidgetsBinding.instance.removeObserver(this);
playerController.removePositionListener(videoPositionListen); playerController.removePositionListener(videoPositionListen);
playerController.removeStatusLister(playerListener);
_plDanmakuController.dispose();
super.dispose(); super.dispose();
} }

View File

@@ -176,10 +176,10 @@ class _SponsorBlockPageState extends State<SponsorBlockPage> {
), ),
body: CustomScrollView( body: CustomScrollView(
slivers: [ slivers: [
SliverToBoxAdapter(child: _blockLimitItem),
SliverToBoxAdapter(child: Divider(height: 1)),
SliverToBoxAdapter(child: _userIdItem), SliverToBoxAdapter(child: _userIdItem),
SliverToBoxAdapter(child: Divider(height: 1)), SliverToBoxAdapter(child: Divider(height: 1)),
SliverToBoxAdapter(child: _blockLimitItem),
SliverToBoxAdapter(child: Divider(height: 1)),
SliverList.separated( SliverList.separated(
itemCount: _blockSettings.length, itemCount: _blockSettings.length,
itemBuilder: (_, index) => ListTile( itemBuilder: (_, index) => ListTile(

View File

@@ -449,15 +449,10 @@ class VideoDetailController extends GetxController
await plPlayerController.videoPlayerController await plPlayerController.videoPlayerController
?.seek(Duration( ?.seek(Duration(
seconds: item.segment.first)); seconds: item.segment.first));
SmartDialog.showToast( _showBlockToast(
'已跳至${Utils.formatDuration(item.segment.first)}', '已跳至${Utils.formatDuration(item.segment.first)}');
displayType: SmartToastType.normal,
);
} catch (e) { } catch (e) {
SmartDialog.showToast( _showBlockToast('跳转失败: $e');
'跳转失败: $e',
displayType: SmartToastType.normal,
);
} }
}, },
style: IconButton.styleFrom( style: IconButton.styleFrom(
@@ -487,6 +482,15 @@ class VideoDetailController extends GetxController
); );
} }
void _showBlockToast(String msg) {
SmartDialog.showToast(
msg,
displayType: SmartToastType.normal,
alignment:
plPlayerController.isFullScreen.value ? Alignment(-0.9, 0.5) : null,
);
}
Future _sponsorBlock() async { Future _sponsorBlock() async {
dynamic result = await Request().get( dynamic result = await Request().get(
'${HttpString.sponsorBlockBaseUrl}/api/skipSegments', '${HttpString.sponsorBlockBaseUrl}/api/skipSegments',
@@ -518,7 +522,6 @@ class VideoDetailController extends GetxController
segmentList.value = (result.data as List) segmentList.value = (result.data as List)
.where((item) => .where((item) =>
enableList.contains(item['category']) && enableList.contains(item['category']) &&
// item['segment'][1] > 0 &&
item['segment'][1] >= item['segment'][0]) item['segment'][1] >= item['segment'][0])
.map( .map(
(item) { (item) {
@@ -555,7 +558,7 @@ class VideoDetailController extends GetxController
); );
}).toList(); }).toList();
} catch (e) { } catch (e) {
debugPrint('filed to parse sponsorblock: $e'); debugPrint('failed to parse sponsorblock: $e');
} }
} }
} }
@@ -588,17 +591,11 @@ class VideoDetailController extends GetxController
?.seek(Duration(seconds: item.segment.second)); ?.seek(Duration(seconds: item.segment.second));
// await plPlayerController // await plPlayerController
// .seekTo(Duration(seconds: item.segment.second)); // .seekTo(Duration(seconds: item.segment.second));
SmartDialog.showToast( _showBlockToast('已跳过${item.segmentType.title}片段');
'已跳过${item.segmentType.title}片段',
displayType: SmartToastType.normal,
);
item.hasSkipped = true; item.hasSkipped = true;
} catch (e) { } catch (e) {
debugPrint('failed to skip: $e'); debugPrint('failed to skip: $e');
SmartDialog.showToast( _showBlockToast('${item.segmentType.title}片段跳过失败');
'${item.segmentType.title}片段跳过失败',
displayType: SmartToastType.normal,
);
} }
} }
break; break;