依赖的组件
dependencies:
video_player: ^2.5.1
chewie: ^1.4.0
使用
import 'package:chewie/chewie.dart';
import 'package:video_player/video_player.dart';
final videoPlayerController = VideoPlayerController.network(
'https://flutter.github.io/assets-for-api-docs/assets/videos/butterfly.mp4');
await videoPlayerController.initialize();
final chewieController = ChewieController(
videoPlayerController: videoPlayerController,
autoPlay: true,
looping: true,
optionsBuilder:(context,defaultOptions)async{
return await showModalBottomSheet(
context:context,
builder:(context){
ListView(
children:[
ListTile(
title:const Text("播放速度"),
ontap:(){
// defaultOptions 建议打印一下检查onTap的下标
defaultOptions[0].onTap!()
}
),
ListTile(
title:const Text("取消"),
ontap:(){
Navigator.of(context).pop();
}
),
]
)
}
)
}
);
final playerWidget = Chewie(
controller: chewieController,
);
// 销毁
@override
void dispose() {
videoPlayerController.dispose();
chewieController.dispose();
super.dispose();
}