当前位置:网站首页>flutter video_player实现监听和自动播放下一首歌曲
flutter video_player实现监听和自动播放下一首歌曲
2022-06-22 13:26:00 【氤氲息】
我的做法是通过监听歌曲的当前位置和总的时长,注意监听的位置,歌曲初始化后开始播放了再进行监听,最后记得销毁
@override
void initState() {
super.initState();
if (_videoPlayerController != null) {
//如果视频控制器存在,清理掉重新创建
_videoPlayerController.removeListener(_videoListener);
_videoPlayerController.dispose();
}
videoplay();
}
videoplay() {
_videoPlayerController = VideoPlayerController.network(
widget.videoList[curIndex])
// _videoPlayerController = VideoPlayerController.file(File("/storage/emulated/0/DCIM/pipixia/eecd00a7e13145ff84568fe4e10ea982.mp4"))
..initialize().then((_) {
// 确保在初始化视频后显示第一帧,直至在按下播放按钮。
setState(() {
_videoPlayerController.play();
});
});
//可以播放就开始监听
_videoPlayerController.addListener(_videoListener);
}
//监听的方法
void _videoListener() {
setState(() {
var curPosition = _videoPlayerController.value.position;
var totalPosition = _videoPlayerController.value.duration;
curPos = curPosition.toString().substring(2, 7);
// curPos=curPos.subString(0,2);
totalPos = totalPosition.toString().substring(2, 7);
print("当前位置${curPos},全部${totalPos}");
//如果当前位置是最后的位置就跳到下一首歌
if (curPosition.toString() != "0:00:00.000000" &&
curPosition == totalPosition) {
setState(() {
curIndex++;
if (curIndex >= widget.videoList.length) {
//循环回到第一首
curIndex = 0;
}
curId = widget.idList[curIndex];
getCommentLists();
videoplay();
});
}
});
}
@override
void dispose() {
_videoPlayerController.dispose();
_videoPlayerController.removeListener(_videoListener);
_commentController.dispose();
_focusNodeComment.dispose();
super.dispose();
}
边栏推荐
- 轻松上手Fluentd,结合 Rainbond 插件市场,日志收集更快捷
- C语言学生管理系统(开源)
- Kukai TV ADB
- MySQL learning notes 2022
- RealNetworks vs. 微软:早期流媒体行业之争
- 数据库中如何使用SQL进行修改&删除
- How to compare the size of two dates in unity and C #
- Struggle, programmer -- Chapter 44: eight hundred miles under one's command, fifty strings turning over the Great Wall
- Struggle, programmer -- Chapter 47 the so-called Iraqis are on the water side
- Messari annual report-2022
猜你喜欢

Thoroughly understand the builder mode (builder)
![[Software Engineering] acquire requirements](/img/52/01320eee5e519910a62f48d604b180.png)
[Software Engineering] acquire requirements

Chip silicon and streaming technology

Kukai TV ADB

Fluentd is easy to get started. Combined with the rainbow plug-in market, log collection is faster

Madcap flare 2022, documentation in language or format

How location coding (PE) works in transformers

Is the encryption market a "natural disaster" or a "man-made disaster" in the cold winter?

网络地址转换NAT

一文搞懂开放源码软件(OSS)质量保证
随机推荐
拜登签署两项旨在加强政府网络安全的新法案
C#定义和实现Interface接口
UE4 通过蓝图获取本地文件
机器学习之感知机
Is the encryption market a "natural disaster" or a "man-made disaster" in the cold winter?
Analysis on data skew of redis slice cluster
Is polardbx PG or MySQL?
作为过来人,写给初入职场的程序员的一些忠告
轻松上手Fluentd,结合 Rainbond 插件市场,日志收集更快捷
先锋期货靠谱么?期货怎么开户安全些?
C# Winform 相册功能,图片缩放,拖拽,预览图分页
Biden signs two new laws aimed at strengthening government cyber security
作为程序员,职业规划需要注意的四个阶段
如何实现接口异常场景测试?测试方法探索与测试工具实现
Groovy list operation
树结构二叉树
Vcip2021: super resolution using decoded information
Using pictures to locate app elements sikulix
[Software Engineering] planning and project management
C#泛型_泛型类