当前位置:网站首页>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();
}
边栏推荐
- As a passer-by, some advice for programmers who are new to the workplace
- 机器学习之随机森林
- Le modèle de diffusion est encore fou! Cette fois - ci, la zone occupée était...
- Nansen Annual Report
- 数据库中如何使用SQL进行修改&删除
- Network address translation nat
- Groovy之闭包
- 11 method reference and constructor application
- Introduction to groovy syntax
- 成都测试设备开发_单片机C语言之数组介绍
猜你喜欢

Neuron+ekuiper realizes data collection, cleaning and anti control of industrial Internet of things

数据采集之:巧用布隆过滤器提取数据摘要

作为程序员,职业规划需要注意的四个阶段

MadCap Flare 2022,语言或格式的文档

Verification code is the natural enemy of automation? See how the great God solved it

Cve - 2022 - 22965 Resume
![Front and back management system of dessert beverage store based on SSM framework dessert mall cake store [source code + database]](/img/1b/9060d58d4dbb7f6f3c3a58959b7f14.png)
Front and back management system of dessert beverage store based on SSM framework dessert mall cake store [source code + database]

芯片硅片与流片技术

基于SSH框架甜品商城管理系统【源码+数据库】

Madcap flare 2022, documentation in language or format
随机推荐
Rongyun: let the bank go to the "cloud" easily
Software architecture
一文彻底弄懂建造者模式(Builder)
Biden signs two new laws aimed at strengthening government cyber security
加密市场进入寒冬,是“天灾”还是“人祸”?
D security can call the system
ThoughtWorks.QRCode和ZXing.Net 二维码,网址可以直接跳转
Loot、USDT
How to use SQL to modify in the database & delete
How MySQL enables multiple auto incrementing columns in a table
Groovy语法介绍
Biden signe deux nouvelles lois visant à renforcer la cybersécurité du Gouvernement
How to solve the problem of amount accuracy in financial applications (take quorum and golang as examples)
As a passer-by, some advice for programmers who are new to the workplace
Fluentd is easy to get started. Combined with the rainbow plug-in market, log collection is faster
11 方法引用和构造器应用
机器学习之感知机
Specific methods and steps of PROFINET communication between s7-200smart and Fanuc robot
Kukai TV ADB
轻松上手Fluentd,结合 Rainbond 插件市场,日志收集更快捷