当前位置:网站首页>flutter video_player實現監聽和自動播放下一首歌曲
flutter video_player實現監聽和自動播放下一首歌曲
2022-06-22 14:50: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();
}
边栏推荐
- 拜登签署两项旨在加强政府网络安全的新法案
- Front and back management system of dessert beverage store based on SSM framework dessert mall cake store [source code + database]
- Installing and using protobuf-c
- How to use SQL to modify in the database & delete
- How location coding (PE) works in transformers
- Madcap flare 2022, documentation in language or format
- 【Pr】基础流程
- Unity sub thread calls UI of main thread
- Error: unable to find a match: lrzsz
- 网络地址转换NAT
猜你喜欢

Database employment consulting system for your help

After reading this article, I will teach you to play with the penetration test target vulnhub - drivetingblues-5

Le modèle de diffusion est encore fou! Cette fois - ci, la zone occupée était...

Deadlock found when trying to get lock; Try restarting transaction

How location coding (PE) works in transformers

Zhongshanshan: engineers after being blasted will take off | ONEFLOW u

RealNetworks vs. 微软:早期流媒体行业之争

Open source SPL redefines OLAP server

基于SSM框架实现的甜品饮品店前后台管理系统甜品商城蛋糕店【源码+数据库】

擴散模型又殺瘋了!這一次被攻占的領域是...
随机推荐
拜登簽署兩項旨在加强政府網絡安全的新法案
Chip silicon and streaming technology
【考研攻略】北京交通大学网络空间安全专业2018-2022年考研数据分析
Lisez ceci pour vous apprendre à jouer avec la cible de test de pénétration vulnhub - driftingblues - 5
Dessert mall management system based on SSH framework [source code + database]
Verification code is the natural enemy of automation? See how the great God solved it
网络地址转换NAT
验证码是自动化的天敌?看看大神是怎么解决的
基于SSH框架甜品商城管理系统【源码+数据库】
Support vector machine for machine learning
【无标题】
芯片硅片与流片技术
d的嵌套赋值
位置编码(PE)是如何在Transformers中发挥作用的
How to implement interface exception scenario testing? Exploration of test methods and implementation of test tools
How to compare the size of two dates in unity and C #
U++ 运营商 学习笔记
Fight, programmer -- Chapter 42 will draw a bow like a full moon, look northwest and shoot Sirius
C # define and implement interface interface
Flink status management