Skip to content

Commit

Permalink
shoot danmaku support
Browse files Browse the repository at this point in the history
  • Loading branch information
Predidit committed Mar 23, 2024
1 parent 8eef7c1 commit 8f9fd98
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 19 deletions.
2 changes: 2 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:oneanime/app_widget.dart';
import 'package:oneanime/request/request.dart';
import 'package:media_kit/media_kit.dart';
import 'package:oneanime/utils/storage.dart';
import 'package:flutter/services.dart';

void main() async {
WidgetsFlutterBinding.ensureInitialized();
Expand All @@ -25,6 +26,7 @@ void main() async {
});
windowManager.setMaximizable(false);
}
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
MediaKit.ensureInitialized();
await GStorage.init();
Request();
Expand Down
118 changes: 99 additions & 19 deletions lib/pages/video/video_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class _VideoPageState extends State<VideoPage> with WindowListener {
playerTimer = getPlayerTimer();
try {
playerController.mediaPlayer.setRate(videoController.playerSpeed);
} catch(e) {
} catch (e) {
debugPrint(e.toString());
}
}
Expand Down Expand Up @@ -224,6 +224,69 @@ class _VideoPageState extends State<VideoPage> with WindowListener {
);
}

/// 发送弹幕 由于接口限制, 暂时未提交云端
void showShootDanmakuSheet() {
final TextEditingController textController = TextEditingController();
bool isSending = false; // 追踪是否正在发送
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text('发送弹幕'),
content: StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
return TextField(
controller: textController,
);
}),
actions: [
TextButton(
onPressed: () => Modular.to.pop(),
child: Text(
'取消',
style: TextStyle(color: Theme.of(context).colorScheme.outline),
),
),
StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
return TextButton(
onPressed: isSending
? null
: () async {
final String msg = textController.text;
if (msg.isEmpty) {
SmartDialog.showToast('弹幕内容不能为空');
return;
} else if (msg.length > 100) {
SmartDialog.showToast('弹幕内容不能超过100个字符');
return;
}
setState(() {
isSending = true; // 开始发送,更新状态
});
// Todo 接口方限制

setState(() {
isSending = false; // 发送结束,更新状态
});
SmartDialog.showToast('发送成功');
danmakuController.addItems([
DanmakuItem(
msg,
// color: Colors.purple,
)
]);
Modular.to.pop();
},
child: Text(isSending ? '发送中...' : '发送'),
);
})
],
);
},
);
}

@override
Widget build(BuildContext context) {
navigationBarState = Platform.isWindows
Expand Down Expand Up @@ -507,29 +570,33 @@ class _VideoPageState extends State<VideoPage> with WindowListener {
)
: Container(),

// 倍速条
// 倍速和发送弹幕
(videoController.showPositioned ||
!playerController.mediaPlayer.state.playing)
? Positioned(
top: 0,
right: 0,
child: SizedBox(
width: 45,
height: 34,
child: TextButton(
style: ButtonStyle(
padding: MaterialStateProperty.all(
EdgeInsets.zero),
),
onPressed: () => showSetSpeedSheet(),
child: Text(
'${videoController.playerSpeed}X',
style: const TextStyle(
color: Colors.white,
fontSize: 12,
child: Row(
children: [
SizedBox(
width: 45,
height: 34,
child: TextButton(
style: ButtonStyle(
padding: MaterialStateProperty.all(
EdgeInsets.zero),
),
onPressed: () => showSetSpeedSheet(),
child: Text(
'${videoController.playerSpeed}X',
style: const TextStyle(
color: Colors.white,
fontSize: 12,
),
),
),
),
),
],
),
)
: Container(),
Expand Down Expand Up @@ -570,6 +637,19 @@ class _VideoPageState extends State<VideoPage> with WindowListener {
},
),
),
IconButton(
color: Colors.white,
icon: const Icon(Icons.notes),
onPressed: () {
if (videoController
.danDanmakus.length ==
0) {
SmartDialog.showToast('当前剧集不支持弹幕发送的说');
return;
}
showShootDanmakuSheet();
},
),
IconButton(
color: Colors.white,
icon: Icon(videoController.danmakuOn
Expand All @@ -592,8 +672,8 @@ class _VideoPageState extends State<VideoPage> with WindowListener {
color: Colors.white,
icon: Icon(
videoController.androidFullscreen
? Icons.fullscreen
: Icons.fullscreen_exit),
? Icons.fullscreen_exit
: Icons.fullscreen),
onPressed: () {
if (videoController.androidFullscreen) {
try {
Expand Down

0 comments on commit 8f9fd98

Please sign in to comment.