feat: 快进、快退、拖动时时间戳展示、关闭自动播放时处理、单p播放完成处理
This commit is contained in:
89
lib/plugin/pl_player/widgets/play_pause_btn.dart
Normal file
89
lib/plugin/pl_player/widgets/play_pause_btn.dart
Normal file
@ -0,0 +1,89 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:media_kit/media_kit.dart';
|
||||
import 'package:pilipala/plugin/pl_player/index.dart';
|
||||
|
||||
class PlayOrPauseButton extends StatefulWidget {
|
||||
final double? iconSize;
|
||||
final Color? iconColor;
|
||||
final PlPlayerController? controller;
|
||||
|
||||
const PlayOrPauseButton({
|
||||
super.key,
|
||||
this.iconSize,
|
||||
this.iconColor,
|
||||
this.controller,
|
||||
});
|
||||
|
||||
@override
|
||||
PlayOrPauseButtonState createState() => PlayOrPauseButtonState();
|
||||
}
|
||||
|
||||
class PlayOrPauseButtonState extends State<PlayOrPauseButton>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late final AnimationController animation;
|
||||
|
||||
StreamSubscription<bool>? subscription;
|
||||
late Player player;
|
||||
bool isOpacity = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
player = widget.controller!.videoPlayerController!;
|
||||
animation = AnimationController(
|
||||
vsync: this,
|
||||
value: player.state.playing ? 1 : 0,
|
||||
duration: const Duration(milliseconds: 200),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
subscription ??= player.stream.playing.listen((event) {
|
||||
if (event) {
|
||||
animation.forward().then((value) => {
|
||||
isOpacity = true,
|
||||
});
|
||||
} else {
|
||||
animation.reverse().then((value) => {isOpacity = false});
|
||||
}
|
||||
setState(() {});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
animation.dispose();
|
||||
subscription?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SizedBox(
|
||||
width: 34,
|
||||
height: 34,
|
||||
child: IconButton(
|
||||
style: ButtonStyle(
|
||||
padding: MaterialStateProperty.all(EdgeInsets.zero),
|
||||
),
|
||||
onPressed: player.playOrPause,
|
||||
color: Colors.white,
|
||||
iconSize: 20,
|
||||
// iconSize: widget.iconSize ?? _theme(context).buttonBarButtonSize,
|
||||
// color: widget.iconColor ?? _theme(context).buttonBarButtonColor,
|
||||
icon: AnimatedIcon(
|
||||
progress: animation,
|
||||
icon: AnimatedIcons.play_pause,
|
||||
color: Colors.white,
|
||||
size: 20,
|
||||
// size: widget.iconSize ?? _theme(context).buttonBarButtonSize,
|
||||
// color: widget.iconColor ?? _theme(context).buttonBarButtonColor,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user