基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。
merge better player from oneAnime
Prediditf0bd2f06c9ef
diff --git a/lib/modules/danmaku/danmaku_module.dart b/lib/modules/danmaku/danmaku_module.dartnew file mode 100644index 00000000..a2d15b33--- /dev/null+++ b/lib/modules/danmaku/danmaku_module.dart@@ -0,0 +1,13 @@+class Danmaku {+ double p;+ String m;++ Danmaku({required this.p, required this.m});++ factory Danmaku.fromJson(Map<String, dynamic> json) {+ List<String> parts = json['p'].split(',');+ double pValue = double.parse(parts[0]);+ String mValue = json['m'];+ return Danmaku(p: pValue, m: mValue);+ }+}\ No newline at end of filediff --git a/lib/pages/player/player_controller.dart b/lib/pages/player/player_controller.dartindex 1d91b976..68e66c84 100644--- a/lib/pages/player/player_controller.dart+++ b/lib/pages/player/player_controller.dart@@ -1,8 +1,14 @@import 'dart:io';import 'package:media_kit/media_kit.dart';import 'package:media_kit_video/media_kit_video.dart';+import 'package:kazumi/modules/danmaku/danmaku_module.dart';import 'package:flutter/material.dart' show debugPrint;import 'package:mobx/mobx.dart';+import 'package:auto_orientation/auto_orientation.dart';+import 'package:window_manager/window_manager.dart';+import 'package:flutter/services.dart';+import 'package:flutter/foundation.dart';+import 'package:device_info_plus/device_info_plus.dart';part 'player_controller.g.dart';@@ -16,7 +22,48 @@ abstract class _PlayerController with Store {late Player mediaPlayer;late VideoController videoController;- @action+ @observable+ Map<int, List<Danmaku>> danDanmakus = {};++ @observable+ bool playing = false;+ @observable+ bool isBuffering = true;+ @observable+ Duration currentPosition = Duration.zero;+ @observable+ Duration buffer = Duration.zero;+ @observable+ Duration duration = Duration.zero;++ // 弹幕开关+ @observable+ bool danmakuOn = false;++ // 界面管理+ @observable+ bool showPositioned = false;+ @observable+ bool showPosition = false;+ @observable+ bool showBrightness = false;+ @observable+ bool showVolume = false;++ // 视频音量/亮度+ @observable+ double volume = 0;+ @observable+ double brightness = 0;++ // 播放器倍速+ @observable+ double playerSpeed = 1.0;++ // 安卓全屏状态+ @observable+ bool androidFullscreen = false;+Future init({int offset = 0}) async {loading = true;try {@@ -25,7 +72,7 @@ abstract class _PlayerController with Store {} catch (e) {debugPrint('未找到已经存在的 player');}- debugPrint('VideoURL开始初始化');+ debugPrint('VideoItem开始初始化');mediaPlayer = await createVideoController();if (offset != 0) {var sub = mediaPlayer.stream.buffer.listen(null);@@ -47,7 +94,7 @@ abstract class _PlayerController with Store {mediaPlayer = Player(configuration: const PlayerConfiguration(// 默认缓存 5M 大小- bufferSize: 5 * 1024 * 1024,+ bufferSize: 5 * 1024 * 1024,),);@@ -81,4 +128,110 @@ abstract class _PlayerController with Store {);return mediaPlayer;}++ Future playOrPause() async {+ // mediaPlayer.state.playing ? danmakuController.pause() : danmakuController.resume();+ await mediaPlayer.playOrPause();+ }++ Future seek(Duration duration) async {+ // danmakuController.clear();+ await mediaPlayer.seek(duration);+ }++ Future pause() async {+ // danmakuController.pause();+ await mediaPlayer.pause();+ }++ Future play() async {+ // danmakuController.resume();+ await mediaPlayer.play();+ }++ Future<void> enterFullScreen() async {+ if (Platform.isWindows || Platform.isLinux || Platform.isMacOS) {+ await windowManager.setFullScreen(true);+ return;+ }+ await SystemChrome.setPreferredOrientations([+ DeviceOrientation.portraitUp,+ ]);+ await landScape();+ await SystemChrome.setEnabledSystemUIMode(+ SystemUiMode.immersiveSticky,+ );+ }++ //退出全屏显示+ Future<void> exitFullScreen() async {+ debugPrint('退出全屏模式');+ if (Platform.isWindows || Platform.isLinux || Platform.isMacOS) {+ await windowManager.setFullScreen(false);+ }+ dynamic document;+ late SystemUiMode mode = SystemUiMode.edgeToEdge;+ try {+ if (kIsWeb) {+ document.exitFullscreen();+ } else if (Platform.isAndroid || Platform.isIOS) {+ if (Platform.isAndroid &&+ (await DeviceInfoPlugin().androidInfo).version.sdkInt < 29) {+ mode = SystemUiMode.manual;+ }+ await SystemChrome.setEnabledSystemUIMode(+ mode,+ overlays: SystemUiOverlay.values,+ );+ // await SystemChrome.setPreferredOrientations([]);+ verticalScreen();+ } else if (Platform.isMacOS || Platform.isWindows || Platform.isLinux) {+ await const MethodChannel('com.alexmercerind/media_kit_video')+ .invokeMethod(+ 'Utils.ExitNativeFullscreen',+ );+ // verticalScreen();+ }+ } catch (exception, stacktrace) {+ debugPrint(exception.toString());+ debugPrint(stacktrace.toString());+ }+ }++ //横屏+ Future<void> landScape() async {+ dynamic document;+ try {+ if (kIsWeb) {+ await document.documentElement?.requestFullscreen();+ } else if (Platform.isAndroid || Platform.isIOS) {+ // await SystemChrome.setEnabledSystemUIMode(+ // SystemUiMode.immersiveSticky,+ // overlays: [],+ // );+ // await SystemChrome.setPreferredOrientations(+ // [+ // DeviceOrientation.landscapeLeft,+ // DeviceOrientation.landscapeRight,+ // ],+ // );+ await AutoOrientation.landscapeAutoMode(forceSensor: true);+ } else if (Platform.isMacOS || Platform.isWindows || Platform.isLinux) {+ await const MethodChannel('com.alexmercerind/media_kit_video')+ .invokeMethod(+ 'Utils.EnterNativeFullscreen',+ );+ }+ } catch (exception, stacktrace) {+ debugPrint(exception.toString());+ debugPrint(stacktrace.toString());+ }+ }++//竖屏+ Future<void> verticalScreen() async {+ await SystemChrome.setPreferredOrientations([+ DeviceOrientation.portraitUp,+ ]);+ }}diff --git a/lib/pages/player/player_controller.g.dart b/lib/pages/player/player_controller.g.dartindex c608a02f..7b26cd9b 100644--- a/lib/pages/player/player_controller.g.dart+++ b/lib/pages/player/player_controller.g.dart@@ -25,18 +25,265 @@ mixin _$PlayerController on _PlayerController, Store {});}- late final _$initAsyncAction =- AsyncAction('_PlayerController.init', context: context);+ late final _$danDanmakusAtom =+ Atom(name: '_PlayerController.danDanmakus', context: context);@override- Future<dynamic> init({int offset = 0}) {- return _$initAsyncAction.run(() => super.init(offset: offset));+ Map<int, List<Danmaku>> get danDanmakus {+ _$danDanmakusAtom.reportRead();+ return super.danDanmakus;+ }++ @override+ set danDanmakus(Map<int, List<Danmaku>> value) {+ _$danDanmakusAtom.reportWrite(value, super.danDanmakus, () {+ super.danDanmakus = value;+ });+ }++ late final _$playingAtom =+ Atom(name: '_PlayerController.playing', context: context);++ @override+ bool get playing {+ _$playingAtom.reportRead();+ return super.playing;+ }++ @override+ set playing(bool value) {+ _$playingAtom.reportWrite(value, super.playing, () {+ super.playing = value;+ });+ }++ late final _$isBufferingAtom =+ Atom(name: '_PlayerController.isBuffering', context: context);++ @override+ bool get isBuffering {+ _$isBufferingAtom.reportRead();+ return super.isBuffering;+ }++ @override+ set isBuffering(bool value) {+ _$isBufferingAtom.reportWrite(value, super.isBuffering, () {+ super.isBuffering = value;+ });+ }++ late final _$currentPositionAtom =+ Atom(name: '_PlayerController.currentPosition', context: context);++ @override+ Duration get currentPosition {+ _$currentPositionAtom.reportRead();+ return super.currentPosition;+ }++ @override+ set currentPosition(Duration value) {+ _$currentPositionAtom.reportWrite(value, super.currentPosition, () {+ super.currentPosition = value;+ });+ }++ late final _$bufferAtom =+ Atom(name: '_PlayerController.buffer', context: context);++ @override+ Duration get buffer {+ _$bufferAtom.reportRead();+ return super.buffer;+ }++ @override+ set buffer(Duration value) {+ _$bufferAtom.reportWrite(value, super.buffer, () {+ super.buffer = value;+ });+ }++ late final _$durationAtom =+ Atom(name: '_PlayerController.duration', context: context);++ @override+ Duration get duration {+ _$durationAtom.reportRead();+ return super.duration;+ }++ @override+ set duration(Duration value) {+ _$durationAtom.reportWrite(value, super.duration, () {+ super.duration = value;+ });+ }++ late final _$danmakuOnAtom =+ Atom(name: '_PlayerController.danmakuOn', context: context);++ @override+ bool get danmakuOn {+ _$danmakuOnAtom.reportRead();+ return super.danmakuOn;+ }++ @override+ set danmakuOn(bool value) {+ _$danmakuOnAtom.reportWrite(value, super.danmakuOn, () {+ super.danmakuOn = value;+ });+ }++ late final _$showPositionedAtom =+ Atom(name: '_PlayerController.showPositioned', context: context);++ @override+ bool get showPositioned {+ _$showPositionedAtom.reportRead();+ return super.showPositioned;+ }++ @override+ set showPositioned(bool value) {+ _$showPositionedAtom.reportWrite(value, super.showPositioned, () {+ super.showPositioned = value;+ });+ }++ late final _$showPositionAtom =+ Atom(name: '_PlayerController.showPosition', context: context);++ @override+ bool get showPosition {+ _$showPositionAtom.reportRead();+ return super.showPosition;+ }++ @override+ set showPosition(bool value) {+ _$showPositionAtom.reportWrite(value, super.showPosition, () {+ super.showPosition = value;+ });+ }++ late final _$showBrightnessAtom =+ Atom(name: '_PlayerController.showBrightness', context: context);++ @override+ bool get showBrightness {+ _$showBrightnessAtom.reportRead();+ return super.showBrightness;+ }++ @override+ set showBrightness(bool value) {+ _$showBrightnessAtom.reportWrite(value, super.showBrightness, () {+ super.showBrightness = value;+ });+ }++ late final _$showVolumeAtom =+ Atom(name: '_PlayerController.showVolume', context: context);++ @override+ bool get showVolume {+ _$showVolumeAtom.reportRead();+ return super.showVolume;+ }++ @override+ set showVolume(bool value) {+ _$showVolumeAtom.reportWrite(value, super.showVolume, () {+ super.showVolume = value;+ });+ }++ late final _$volumeAtom =+ Atom(name: '_PlayerController.volume', context: context);++ @override+ double get volume {+ _$volumeAtom.reportRead();+ return super.volume;+ }++ @override+ set volume(double value) {+ _$volumeAtom.reportWrite(value, super.volume, () {+ super.volume = value;+ });+ }++ late final _$brightnessAtom =+ Atom(name: '_PlayerController.brightness', context: context);++ @override+ double get brightness {+ _$brightnessAtom.reportRead();+ return super.brightness;+ }++ @override+ set brightness(double value) {+ _$brightnessAtom.reportWrite(value, super.brightness, () {+ super.brightness = value;+ });+ }++ late final _$playerSpeedAtom =+ Atom(name: '_PlayerController.playerSpeed', context: context);++ @override+ double get playerSpeed {+ _$playerSpeedAtom.reportRead();+ return super.playerSpeed;+ }++ @override+ set playerSpeed(double value) {+ _$playerSpeedAtom.reportWrite(value, super.playerSpeed, () {+ super.playerSpeed = value;+ });+ }++ late final _$androidFullscreenAtom =+ Atom(name: '_PlayerController.androidFullscreen', context: context);++ @override+ bool get androidFullscreen {+ _$androidFullscreenAtom.reportRead();+ return super.androidFullscreen;+ }++ @override+ set androidFullscreen(bool value) {+ _$androidFullscreenAtom.reportWrite(value, super.androidFullscreen, () {+ super.androidFullscreen = value;+ });}@overrideString toString() {return '''-loading: ${loading}+loading: ${loading},+danDanmakus: ${danDanmakus},+playing: ${playing},+isBuffering: ${isBuffering},+currentPosition: ${currentPosition},+buffer: ${buffer},+duration: ${duration},+danmakuOn: ${danmakuOn},+showPositioned: ${showPositioned},+showPosition: ${showPosition},+showBrightness: ${showBrightness},+showVolume: ${showVolume},+volume: ${volume},+brightness: ${brightness},+playerSpeed: ${playerSpeed},+androidFullscreen: ${androidFullscreen}''';}}diff --git a/lib/pages/player/player_item.dart b/lib/pages/player/player_item.dartindex 3e8726b6..f8a4e524 100644--- a/lib/pages/player/player_item.dart+++ b/lib/pages/player/player_item.dart@@ -1,11 +1,19 @@import 'dart:io';-+import 'dart:async';+import 'package:flutter/widgets.dart';+import 'package:flutter/services.dart';+import 'package:flutter/gestures.dart';import 'package:kazumi/pages/player/player_controller.dart';import 'package:flutter/material.dart';+import 'package:kazumi/utils/utils.dart';import 'package:flutter_mobx/flutter_mobx.dart';import 'package:media_kit_video/media_kit_video.dart';import 'package:flutter_modular/flutter_modular.dart';import 'package:kazumi/pages/video/video_controller.dart';+import 'package:window_manager/window_manager.dart';+import 'package:screen_brightness/screen_brightness.dart';+import 'package:audio_video_progress_bar/audio_video_progress_bar.dart';+import 'package:flutter_volume_controller/flutter_volume_controller.dart';class PlayerItem extends StatefulWidget {const PlayerItem({super.key});@@ -14,16 +22,117 @@ class PlayerItem extends StatefulWidget {State<PlayerItem> createState() => _PlayerItemState();}-class _PlayerItemState extends State<PlayerItem> {+class _PlayerItemState extends State<PlayerItem> with WindowListener {final PlayerController playerController = Modular.get<PlayerController>();final VideoPageController videoPageController =Modular.get<VideoPageController>();+ final FocusNode _focusNode = FocusNode();++ // 弹幕+ final _danmuKey = GlobalKey();++ Timer? hideTimer;+ Timer? playerTimer;+ Timer? mouseScrollerTimer;++ void _handleTap() {+ playerController.showPositioned = true;+ if (hideTimer != null) {+ hideTimer!.cancel();+ }++ hideTimer = Timer(const Duration(seconds: 4), () {+ playerController.showPositioned = false;+ hideTimer = null;+ });+ }++ void _handleMouseScroller() {+ playerController.showVolume = true;+ if (mouseScrollerTimer != null) {+ mouseScrollerTimer!.cancel();+ }++ mouseScrollerTimer = Timer(const Duration(seconds: 2), () {+ playerController.showVolume = false;+ mouseScrollerTimer = null;+ });+ }++ getPlayerTimer() {+ return Timer.periodic(const Duration(seconds: 1), (timer) {+ playerController.playing = playerController.mediaPlayer.state.playing;+ playerController.isBuffering =+ playerController.mediaPlayer.state.buffering;+ playerController.currentPosition =+ playerController.mediaPlayer.state.position;+ playerController.buffer = playerController.mediaPlayer.state.buffer;+ playerController.duration = playerController.mediaPlayer.state.duration;+ // 弹幕相关+ // if (playerController.currentPosition.inMicroseconds != 0 &&+ // playerController.mediaPlayer.state.playing == true &&+ // playerController.danmakuOn == true) {+ // // debugPrint('当前播放到 ${videoController.currentPosition.inSeconds}');+ // playerController.danDanmakus[playerController.currentPosition.inSeconds]+ // ?.asMap()+ // .forEach((idx, danmaku) async {+ // await Future.delayed(+ // Duration(+ // milliseconds: idx *+ // 1000 ~/+ // playerController+ // .danDanmakus[+ // playerController.currentPosition.inSeconds]!+ // .length),+ // () => mounted && playerController.mediaPlayer.state.playing+ // ? danmakuController.addItems([DanmakuItem(danmaku.m)])+ // : null);+ // });+ // }+ // 自动播放下一集+ // if (playerController.mediaPlayer.state.completed == true &&+ // videoController.episode < videoController.token.length) {+ // videoController.changeEpisode(videoController.episode + 1);+ // }+ windowManager.addListener(this);+ });+ }++ void onBackPressed(BuildContext context) {+ if (playerController.androidFullscreen) {+ debugPrint('当前播放器全屏');+ try {+ // danmakuController.onClear();+ } catch (_) {}+ try {+ playerController.exitFullScreen();+ playerController.androidFullscreen = false;+ return;+ } catch (e) {+ debugPrint(e.toString());+ }+ }+ debugPrint('当前播放器非全屏');+ Navigator.of(context).pop();+ }++ Future<void> setVolume(double value) async {+ try {+ FlutterVolumeController.updateShowSystemUI(false);+ await FlutterVolumeController.setVolume(value);+ } catch (_) {}+ }++ Future<void> setBrightness(double value) async {+ try {+ await ScreenBrightness().setScreenBrightness(value);+ } catch (_) {}+ }@overridevoid initState() {super.initState();- // debugPrint('在小部件中初始化');- // playerController.init;+ playerTimer = getPlayerTimer();}@override@@ -34,15 +143,665 @@ class _PlayerItemState extends State<PlayerItem> {@overrideWidget build(BuildContext context) {+ return PopScope(+ // key: _key,+ canPop: false,+ onPopInvoked: (bool didPop) async {+ onBackPressed(context);+ },+ child: SafeArea(+ child: Scaffold(+ body: Observer(builder: (context) {+ return Column(+ children: [+ Container(+ color: Colors.black,+ child: MouseRegion(+ onHover: (_) {+ _handleTap();+ },+ child: FocusTraversalGroup(+ child: FocusScope(+ node: FocusScopeNode(),+ child: Listener(+ onPointerSignal: (pointerSignal) {+ if (pointerSignal is PointerScrollEvent) {+ _handleMouseScroller();+ final scrollDelta = pointerSignal.scrollDelta;+ debugPrint('滚轮滑动距离: ${scrollDelta.dy}');+ final double volume = playerController.volume -+ scrollDelta.dy / 6000;+ final double result = volume.clamp(0.0, 1.0);+ setVolume(result);+ playerController.volume = result;+ }+ },+ child: KeyboardListener(+ autofocus: true,+ focusNode: _focusNode,+ onKeyEvent: (KeyEvent event) {+ if (event is KeyDownEvent) {+ // 当空格键被按下时+ _handleTap();+ if (event.logicalKey ==+ LogicalKeyboardKey.space) {+ debugPrint('空格键被按下');+ try {+ playerController.playOrPause();+ } catch (e) {+ debugPrint(e.toString());+ }+ }+ // 右方向键被按下+ if (event.logicalKey ==+ LogicalKeyboardKey.arrowRight) {+ debugPrint('右方向键被按下');+ try {+ if (playerTimer != null) {+ playerTimer!.cancel();+ }+ playerController.currentPosition = Duration(+ seconds: playerController+ .currentPosition.inSeconds ++ 10);+ playerController+ .seek(playerController.currentPosition);+ playerTimer = getPlayerTimer();+ } catch (e) {+ debugPrint(e.toString());+ }+ }+ // 左方向键被按下+ if (event.logicalKey ==+ LogicalKeyboardKey.arrowLeft) {+ if (playerController+ .currentPosition.inSeconds >+ 10) {+ try {+ if (playerTimer != null) {+ playerTimer!.cancel();+ }+ playerController.currentPosition =+ Duration(+ seconds: playerController+ .currentPosition+ .inSeconds -+ 10);+ playerController.seek(+ playerController.currentPosition);+ playerTimer = getPlayerTimer();+ } catch (e) {+ debugPrint(e.toString());+ }+ }+ }+ // Esc键被按下+ if (event.logicalKey ==+ LogicalKeyboardKey.escape) {+ if (playerController.androidFullscreen) {+ try {+ // danmakuController.onClear();+ } catch (_) {}+ playerController.exitFullScreen();+ playerController.androidFullscreen =+ !playerController.androidFullscreen;+ }+ }+ }+ },+ child: SizedBox(+ height: playerController.androidFullscreen+ ? (MediaQuery.of(context).size.height)+ : (MediaQuery.of(context).size.width *+ 9.0 /+ (16.0)),+ width: MediaQuery.of(context).size.width,+ child:+ Stack(alignment: Alignment.center, children: [+ Center(child: playerSurface),+ playerController.isBuffering+ ? const Positioned.fill(+ child: Center(+ child: CircularProgressIndicator(),+ ),+ )+ : Container(),+ GestureDetector(+ onTap: () async {+ _handleTap;+ try {+ playerController.volume =+ await FlutterVolumeController+ .getVolume() ??+ playerController.volume;+ } catch (e) {+ debugPrint(e.toString());+ }+ },+ child: Container(+ color: Colors.transparent,+ width: double.infinity,+ height: double.infinity,+ ),+ ),++ // 播放器手势控制+ Positioned.fill(+ left: 16,+ top: 25,+ right: 15,+ bottom: 15,+ child: Platform.isWindows ||+ Platform.isLinux ||+ Platform.isMacOS+ ? Container()+ : GestureDetector(+ onHorizontalDragUpdate:+ (DragUpdateDetails details) {+ playerController.showPosition =+ true;+ if (playerTimer != null) {+ // debugPrint('检测到拖动, 定时器取消');+ playerTimer!.cancel();+ }+ playerController.pause();+ final double scale = 180000 /+ MediaQuery.sizeOf(context)+ .width;+ playerController.currentPosition =+ Duration(+ milliseconds:+ playerController+ .currentPosition+ .inMilliseconds ++ (details.delta.dx *+ scale)+ .round());+ }, onHorizontalDragEnd:+ (DragEndDetails details) {+ playerController.seek(+ playerController+ .currentPosition);+ playerController.play();+ playerTimer = getPlayerTimer();+ playerController.showPosition =+ false;+ }, onVerticalDragUpdate:+ (DragUpdateDetails+ details) async {+ final double totalWidth =+ MediaQuery.sizeOf(context)+ .width;+ final double totalHeight =+ MediaQuery.sizeOf(context)+ .height;+ final double tapPosition =+ details.localPosition.dx;+ final double sectionWidth =+ totalWidth / 2;+ final double delta =+ details.delta.dy;++ /// 非全屏时禁用+ if (!playerController+ .androidFullscreen) {+ return;+ }+ if (tapPosition < sectionWidth) {+ // 左边区域+ playerController.showBrightness =+ true;+ try {+ playerController.brightness =+ await ScreenBrightness()+ .current;+ } catch (e) {+ debugPrint(e.toString());+ }+ final double level =+ (totalHeight) * 3;+ final double brightness =+ playerController.brightness -+ delta / level;+ final double result =+ brightness.clamp(0.0, 1.0);+ setBrightness(result);+ } else {+ // 右边区域+ playerController.showVolume =+ true;+ final double level =+ (totalHeight) * 3;+ final double volume =+ playerController.volume -+ delta / level;+ final double result =+ volume.clamp(0.0, 1.0);+ setVolume(result);+ playerController.volume = result;+ }+ }, onVerticalDragEnd:+ (DragEndDetails details) {+ playerController.showBrightness =+ false;+ playerController.showVolume = false;+ })),+ // 顶部进度条+ Positioned(+ top: 25,+ width: 200,+ child: playerController.showPosition+ ? Wrap(+ alignment: WrapAlignment.center,+ children: <Widget>[+ Container(+ padding:+ const EdgeInsets.all(8.0),+ decoration: BoxDecoration(+ color: Colors.black+ .withOpacity(0.5),+ borderRadius:+ BorderRadius.circular(+ 8.0), // 圆角+ ),+ child: Text(+ playerController+ .currentPosition+ .compareTo(+ playerController+ .mediaPlayer+ .state+ .position) >+ 0+ ? '快进 ${playerController.currentPosition.inSeconds - playerController.mediaPlayer.state.position.inSeconds} 秒'+ : '快退 ${playerController.mediaPlayer.state.position.inSeconds - playerController.currentPosition.inSeconds} 秒',+ style: const TextStyle(+ color: Colors.white,+ ),+ ),+ ),+ ],+ )+ : Container()),+ // 亮度条+ Positioned(+ top: 25,+ child: playerController.showBrightness+ ? Wrap(+ alignment: WrapAlignment.center,+ children: <Widget>[+ Container(+ padding:+ const EdgeInsets.all(8.0),+ decoration: BoxDecoration(+ color: Colors.black+ .withOpacity(0.5),+ borderRadius:+ BorderRadius.circular(+ 8.0), // 圆角+ ),+ child: Row(+ children: <Widget>[+ const Icon(+ Icons.brightness_7,+ color: Colors.white),+ Text(+ ' ${(playerController.brightness * 100).toInt()} %',+ style: const TextStyle(+ color: Colors.white,+ ),+ ),+ ],+ )),+ ],+ )+ : Container()),+ // 音量条+ Positioned(+ top: 25,+ child: playerController.showVolume+ ? Wrap(+ alignment: WrapAlignment.center,+ children: <Widget>[+ Container(+ padding:+ const EdgeInsets.all(8.0),+ decoration: BoxDecoration(+ color: Colors.black+ .withOpacity(0.5),+ borderRadius:+ BorderRadius.circular(+ 8.0), // 圆角+ ),+ child: Row(+ children: <Widget>[+ const Icon(+ Icons.volume_down,+ color: Colors.white),+ Text(+ ' ${(playerController.volume * 100).toInt()}%',+ style: const TextStyle(+ color: Colors.white,+ ),+ ),+ ],+ )),+ ],+ )+ : Container()),+ // Positioned(+ // top: 0,+ // left: 0,+ // right: 0,+ // height: playerController.androidFullscreen+ // ? MediaQuery.sizeOf(context).height *+ // danmakuArea+ // : (MediaQuery.sizeOf(context).width *+ // 9 /+ // 16 *+ // danmakuArea),+ // child: DanmakuView(+ // key: _danmuKey,+ // createdController: (DanmakuController e) {+ // danmakuController = e;+ // playerController.danmakuController = e;+ // debugPrint('弹幕控制器创建成功');+ // },+ // option: DanmakuOption(+ // hideTop: _hideTop,+ // hideScroll: _hideScroll,+ // hideBottom: _hideBottom,+ // opacity: _opacity,+ // fontSize: _fontSize,+ // duration: _duration,+ // ),+ // statusChanged: (e) {},+ // ),+ // ),++ // 自定义顶部组件+ (playerController.showPositioned ||+ !playerController+ .mediaPlayer.state.playing)+ ? Positioned(+ top: 0,+ left: 0,+ right: 0,+ child: Row(+ children: [+ IconButton(+ color: Colors.white,+ icon:+ const Icon(Icons.arrow_back),+ onPressed: () {+ if (playerController+ .androidFullscreen ==+ true) {+ playerController+ .exitFullScreen();+ playerController+ .androidFullscreen =+ false;+ return;+ }+ Navigator.of(context).pop();+ },+ ),+ // 拖动条+ // const Expanded(+ // child: dtb.DragToMoveArea(+ // child: SizedBox(height: 40)),+ // ),+ TextButton(+ style: ButtonStyle(+ padding:+ MaterialStateProperty.all(+ EdgeInsets.zero),+ ),+ onPressed: () {+ // 倍速播放+ // showSetSpeedSheet();+ },+ child: Text(+ '${playerController.playerSpeed}X',+ style: const TextStyle(+ color: Colors.white,+ fontSize: 12,+ ),+ ),+ ),+ // 追番+ // IconButton(+ // icon: (videoController.follow)+ // ? Icon(Icons.favorite,+ // color: Colors.white)+ // : Icon(Icons.favorite_border,+ // color: Colors.white),+ // onPressed: () {+ // popularController.updateFollow(+ // videoController.link,+ // !(videoController.follow));+ // videoController.follow =+ // !videoController.follow;+ // SmartDialog.showToast(+ // videoController.follow+ // ? '自己追的番要好好看完哦'+ // : '取消追番成功',+ // displayType:+ // SmartToastType.last);+ // },+ // splashColor: Theme.of(context)+ // .colorScheme+ // .tertiary+ // .withOpacity(0.5),+ // ),+ ],+ ),+ )+ : Container(),++ // 自定义播放器底部组件+ (playerController.showPositioned ||+ !playerController+ .mediaPlayer.state.playing)+ ? Positioned(+ bottom: 0,+ left: 0,+ right: 0,+ child: Row(+ children: [+ IconButton(+ color: Colors.white,+ icon: Icon(+ playerController.playing+ ? Icons.pause+ : Icons.play_arrow),+ onPressed: () {+ if (playerController.playing) {+ playerController.pause();+ } else {+ playerController.play();+ }+ },+ ),+ // 更换选集+ // (playerController+ // .androidFullscreen ==+ // true)+ // ? IconButton(+ // color: Colors.white,+ // icon: const Icon(+ // Icons.skip_next),+ // onPressed: () {+ // if (videoController+ // .episode ==+ // videoController+ // .token.length) {+ // SmartDialog.showToast(+ // '已经是最新一集',+ // displayType:+ // SmartToastType+ // .last);+ // return;+ // }+ // SmartDialog.showToast(+ // '第 ${videoController.episode + 1} 话');+ // videoController+ // .changeEpisode(+ // videoController+ // .episode ++ // 1);+ // },+ // )+ // : Container(),+ Expanded(+ child: ProgressBar(+ timeLabelLocation:+ TimeLabelLocation.none,+ progress: playerController+ .currentPosition,+ buffered:+ playerController.buffer,+ total:+ playerController.duration,+ onSeek: (duration) {+ playerController+ .seek(duration);+ },+ ),+ ),+ ((Platform.isAndroid ||+ Platform.isIOS) &&+ !playerController+ .androidFullscreen)+ ? Container()+ : Container(+ padding:+ const EdgeInsets.only(+ left: 10.0),+ child: Text(+ Utils.durationToString(+ playerController+ .currentPosition) ++ " / " ++ Utils.durationToString(+ playerController+ .duration),+ style: TextStyle(+ color: Colors.white,+ fontSize: Platform+ .isWindows ||+ Platform+ .isLinux ||+ Platform.isMacOS+ ? 16.0+ : 12.0,+ ),+ ),+ ),+ // 弹幕相关+ // (playerController.androidFullscreen ==+ // true &&+ // playerController.danmakuOn ==+ // true)+ // ? IconButton(+ // color: Colors.white,+ // icon:+ // const Icon(Icons.notes),+ // onPressed: () {+ // if (playerController+ // .danDanmakus+ // .length ==+ // 0) {+ // SmartDialog.showToast(+ // '当前剧集不支持弹幕发送的说',+ // displayType:+ // SmartToastType+ // .last);+ // return;+ // }+ // showShootDanmakuSheet();+ // },+ // )+ // : Container(),+ // IconButton(+ // color: Colors.white,+ // icon: Icon(videoController+ // .danmakuOn+ // ? Icons.comment+ // : Icons.comments_disabled),+ // onPressed: () {+ // if (videoController+ // .danDanmakus.length ==+ // 0) {+ // SmartDialog.showToast(+ // '当前剧集没有找到弹幕的说',+ // displayType:+ // SmartToastType.last);+ // return;+ // }+ // danmakuController.clear();+ // videoController.danmakuOn =+ // !videoController.danmakuOn;+ // debugPrint(+ // '弹幕开关变更为 ${videoController.danmakuOn}');+ // },+ // ),+ IconButton(+ color: Colors.white,+ icon: Icon(playerController+ .androidFullscreen+ ? Icons.fullscreen_exit+ : Icons.fullscreen),+ onPressed: () {+ if (playerController+ .androidFullscreen) {+ try {+ // 弹幕相关+ // danmakuController.onClear();+ } catch (_) {}+ playerController+ .exitFullScreen();+ } else {+ playerController+ .enterFullScreen();+ }+ playerController+ .androidFullscreen =+ !playerController+ .androidFullscreen;+ },+ ),+ ],+ ),+ )+ : Container(),+ ]),+ ),+ ),+ ),+ ),+ ),+ ),+ ),+ // SizedBox(child: Text("${videoController.androidFullscreen}")),+ ],+ );+ }),+ ),+ ),+ );+ }++ Widget get playerSurface {return Column(children: [// const Text('Video Player Test'),Observer(builder: (context) {return Expanded(- child: playerController.loading ? const Center(child: CircularProgressIndicator()) : Video(+ child: Video(controller: playerController.videoController,- // 测试 等待引入现代面板- // controls: NoVideoControls,+ controls: NoVideoControls,subtitleViewConfiguration: SubtitleViewConfiguration(style: TextStyle(color: Colors.pink, // 深粉色字体diff --git a/lib/pages/video/video_page.dart b/lib/pages/video/video_page.dartindex 226c756a..d234ceab 100644--- a/lib/pages/video/video_page.dart+++ b/lib/pages/video/video_page.dart@@ -88,7 +88,7 @@ class _VideoPageState extends State<VideoPage>: Container(),)),Positioned.fill(- child: (!videoPageController.currentPlugin.useNativePlayer)+ child: (!videoPageController.currentPlugin.useNativePlayer || playerController.loading)? Container(): const PlayerItem(),),diff --git a/lib/request/api.dart b/lib/request/api.dartindex f42ed3db..d351aef8 100644--- a/lib/request/api.dart+++ b/lib/request/api.dart@@ -9,4 +9,8 @@ class Api {static const String bangumiSearch = 'https://api.bgm.tv/search/subject/';// 条目搜索static const String bangumiRankSearch = 'https://api.bgm.tv/v0/search/subjects';+ // 弹弹Play+ static const String dandanAPI = "https://api.dandanplay.net/api/v2/comment/";+ static const String dandanSearch = "https://api.dandanplay.net/api/v2/search/anime";+ static const String dandanInfo = "https://api.dandanplay.net/api/v2/bangumi/";}\ No newline at end of filediff --git a/lib/request/damaku.dart b/lib/request/damaku.dartnew file mode 100644index 00000000..ba1afdc5--- /dev/null+++ b/lib/request/damaku.dart@@ -0,0 +1,66 @@+import 'package:dio/dio.dart';+import 'package:kazumi/request/request.dart';+import 'package:kazumi/request/api.dart';+import 'package:flutter/material.dart' as material;+import 'package:kazumi/modules/danmaku/danmaku_module.dart';++class DanmakuRequest {++ //获取弹弹Play集合,需要进一步处理+ static getBangumiID(String title) async {+ var httpHeaders = {+ 'user-agent':+ 'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_3_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.4 Safari/605.1.15',+ 'referer': '',+ };+ Map<String, String> keywordMap = {+ 'keyword': title,+ };++ final res = await Request().get(Api.dandanSearch,+ data: keywordMap, options: Options(headers: httpHeaders));+ Map<String, dynamic> jsonData = res.data;+ List<dynamic> animes = jsonData['animes'];++ // 保留此判断以防止错误匹配+ int minAnimeId = 100000;+ for (var anime in animes) {+ int animeId = anime['animeId'];+ if (animeId < minAnimeId && animeId >= 8692) {+ minAnimeId = animeId;+ }+ }+ // 这里猜测了弹弹Play的分集命名规则,例如上面的番剧ID为1758,第一集弹幕库ID大概率为17580001,但是此命名规则并没有体现在官方API文档里,保险的做法是请求 Api.dandanInfo+ return minAnimeId;+ }++ static getDanDanmaku(int bangumiID, int episode) async {+ List<Danmaku> danmakus = [];+ if (bangumiID == 100000) {+ return danmakus;+ }+ var httpHeaders = {+ 'user-agent':+ 'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_3_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.4 Safari/605.1.15',+ 'referer': '',+ };+ Map<String, String> withRelated = {+ 'withRelated': 'true',+ };+ material.debugPrint(+ "弹幕请求最终URL ${Api.dandanAPI + "$bangumiID" + episode.toString().padLeft(4, '0')}");+ final res = await Request().get(+ (Api.dandanAPI + "$bangumiID" + episode.toString().padLeft(4, '0')),+ data: withRelated,+ options: Options(headers: httpHeaders));++ Map<String, dynamic> jsonData = res.data;+ List<dynamic> comments = jsonData['comments'];++ for (var comment in comments) {+ Danmaku danmaku = Danmaku.fromJson(comment);+ danmakus.add(danmaku);+ }+ return danmakus;+ }+}diff --git a/lib/utils/utils.dart b/lib/utils/utils.dartindex ec1b4a0e..a5395b47 100644--- a/lib/utils/utils.dart+++ b/lib/utils/utils.dart@@ -323,4 +323,11 @@ class Utils {static void copyToClipboard(String text) {Clipboard.setData(ClipboardData(text: text));}++ static String durationToString(Duration duration) {+ String pad(int n) => n.toString().padLeft(2, '0');+ var minutes = pad(duration.inMinutes % 60);+ var seconds = pad(duration.inSeconds % 60);+ return "$minutes:$seconds";+ }}