feat: seek from viewpoint

Closes #153

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-01-13 12:21:25 +08:00
parent 042b69cc05
commit 5707c08011
4 changed files with 67 additions and 5 deletions

View File

@@ -75,7 +75,7 @@ class SegmentProgressBar extends CustomPainter {
canvas.drawRect(
Rect.fromLTRB(
0,
-_defHeight,
-_defHeight - 2,
size.width,
0,
),
@@ -86,9 +86,9 @@ class SegmentProgressBar extends CustomPainter {
canvas.drawRect(
Rect.fromLTWH(
segmentStart,
-_defHeight,
-_defHeight - 2,
segmentEnd == segmentStart ? 2 : segmentEnd - segmentStart,
size.height + _defHeight,
size.height + _defHeight + 2,
),
paint,
);
@@ -98,7 +98,7 @@ class SegmentProgressBar extends CustomPainter {
: (segmentStart - prevStart - textPainter.width) / 2 +
prevStart +
1;
double textY = (-_defHeight - textPainter.height) / 2;
double textY = (-_defHeight - textPainter.height) / 2 - 1;
textPainter.paint(canvas, Offset(textX, textY));
} else {
canvas.drawRect(

View File

@@ -2001,7 +2001,7 @@ class VideoDetailController extends GetxController
return Segment(
start,
start,
Colors.black87,
Colors.black.withOpacity(0.5),
item?['content'],
item?['imgUrl'],
item?['from'],

View File

@@ -1052,6 +1052,37 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
child: Stack(
alignment: Alignment.bottomCenter,
children: [
if (plPlayerController.viewPointList.isNotEmpty &&
plPlayerController.showVP.value)
LayoutBuilder(
builder: (context, constraints) {
return SizedBox(
height: 20,
child: Listener(
behavior: HitTestBehavior.translucent,
onPointerDown: (event) {
try {
double seg = event.localPosition.dx /
constraints.maxWidth;
Segment item = plPlayerController
.viewPointList
.where((item) {
return item.start >= seg;
}).reduce((a, b) =>
a.start < b.start ? a : b);
if (item.from != null) {
plPlayerController.seekTo(
Duration(seconds: item.from!));
}
// debugPrint('${item.title},,${item.from}');
} catch (e) {
debugPrint('$e');
}
},
),
);
},
),
ProgressBar(
progress: Duration(seconds: value),
buffered: Duration(seconds: buffer),

View File

@@ -52,6 +52,37 @@ class BottomControl extends StatelessWidget implements PreferredSizeWidget {
child: Stack(
alignment: Alignment.bottomCenter,
children: [
if (controller?.viewPointList.isNotEmpty == true &&
controller?.showVP.value == true)
LayoutBuilder(
builder: (context, constraints) {
return Container(
height: 20,
margin: const EdgeInsets.only(bottom: 5.25),
child: Listener(
behavior: HitTestBehavior.translucent,
onPointerDown: (event) {
try {
double seg = event.localPosition.dx /
constraints.maxWidth;
Segment? item = controller?.viewPointList
.where((item) {
return item.start >= seg;
}).reduce((a, b) =>
a.start < b.start ? a : b);
if (item?.from != null) {
controller?.seekTo(
Duration(seconds: item!.from!));
}
// debugPrint('${item?.title},,${item?.from}');
} catch (e) {
debugPrint('$e');
}
},
),
);
},
),
ProgressBar(
progress: Duration(seconds: value),
buffered: Duration(seconds: buffer),