当前位置:网站首页>flutter video_ Player monitors and automatically plays the next song
flutter video_ Player monitors and automatically plays the next song
2022-06-22 14:50:00 【Dense information】
Reference resources
Reference resources
My approach is to monitor the current position and total duration of the song , Pay attention to the listening position , Listen after the song starts playing after initialization , Finally, remember to destroy
@override
void initState() {
super.initState();
if (_videoPlayerController != null) {
// If the video controller is present , Clean up and recreate
_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((_) {
// Make sure to display the first frame after initializing the video , Until the play button is pressed .
setState(() {
_videoPlayerController.play();
});
});
// Start listening when you can play
_videoPlayerController.addListener(_videoListener);
}
// How to monitor
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(" The current position ${curPos}, All ${totalPos}");
// If the current position is the last position, jump to the next song
if (curPosition.toString() != "0:00:00.000000" &&
curPosition == totalPosition) {
setState(() {
curIndex++;
if (curIndex >= widget.videoList.length) {
// Loop back to first
curIndex = 0;
}
curId = widget.idList[curIndex];
getCommentLists();
videoplay();
});
}
});
}
@override
void dispose() {
_videoPlayerController.dispose();
_videoPlayerController.removeListener(_videoListener);
_commentController.dispose();
_focusNodeComment.dispose();
super.dispose();
}
边栏推荐
- Kukai TV ADB
- Messari annual report-2022
- PHP内置协议(支持的协议和封装协议)
- C # WinForm photo album function, picture zooming, dragging, preview Pagination
- Loot、USDT
- RealNetworks vs. 微软:早期流媒体行业之争
- 【毕业设计】基于半监督学习和集成学习的情感分析研究
- How MySQL enables multiple auto incrementing columns in a table
- How location coding (PE) works in transformers
- Front and back management system of dessert beverage store based on SSM framework dessert mall cake store [source code + database]
猜你喜欢

Lisez ceci pour vous apprendre à jouer avec la cible de test de pénétration vulnhub - driftingblues - 5

Madcap flare 2022, documentation in language or format

Specific methods and steps of PROFINET communication between s7-200smart and Fanuc robot

phpStudy 2016搭建-pikachu靶场
![[Software Engineering] design module](/img/08/d55af729a8241e109fdeb96c896670.png)
[Software Engineering] design module
![[untitled]](/img/ff/f23e5275683d4d7b13fcb94cc77702.png)
[untitled]
![[introduction to postgraduate entrance examination] analysis of postgraduate entrance examination data of Cyberspace Security Major of Beijing Jiaotong University from 2018 to 2022](/img/84/b572b3b80cc0dd1489076116cf0638.png)
[introduction to postgraduate entrance examination] analysis of postgraduate entrance examination data of Cyberspace Security Major of Beijing Jiaotong University from 2018 to 2022

Understand the quality assurance of open source software (OSS)

Deadlock found when trying to get lock; Try restarting transaction

Verification code is the natural enemy of automation? See how the great God solved it
随机推荐
[introduction to postgraduate entrance examination] analysis of postgraduate entrance examination data of Cyberspace Security Major of Beijing Jiaotong University from 2018 to 2022
C language student management system (open source)
Chengdu test equipment development_ Array introduction of C language for single chip microcomputer
11 方法引用和构造器应用
C generic method
芯片硅片与流片技术
[PR] basic process
本周四晚19:00战码先锋第7期直播丨三方应用开发者如何为开源做贡献
C# Winform 相册功能,图片缩放,拖拽,预览图分页
How to implement interface exception scenario testing? Exploration of test methods and implementation of test tools
C#定义和实现Interface接口
Madcap flare 2022, documentation in language or format
Random forest of machine learning
Unity prevents the BTN button from being clicked continuously
Flink status management
一文彻底弄懂工厂模式(Factory)
Le modèle de diffusion est encore fou! Cette fois - ci, la zone occupée était...
MySQL learning notes 2022
unity和C#中怎么去比较2个日期大小
一篇博客让你了解Material Design的使用