问题描述
我正在使用该库来实现视频功能。
https://pub.dev/packages/video_player
就目前而言,我已经使它成功了。
我想拥有的只是简单的控制器,例如OS基本播放器,没有可以设计的。
我想有一种无需重新发明轮子就能更轻松地实现接口的方法...
我正确吗?
我在Google周围搜索,但找不到。
解决方法
您可以使用软件包https://pub.dev/packages/chewie video_player
插件提供了对视频播放的低级访问。 Chewie
在引擎盖下使用video_player
并将其包装在友好的Material
或Cupertino
UI中!
示例代码的工作演示
示例代码https://github.com/brianegan/chewie/tree/master/example
import 'package:chewie/chewie.dart';
import 'package:chewie/src/chewie_player.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';
void main() {
runApp(
ChewieDemo(),);
}
class ChewieDemo extends StatefulWidget {
ChewieDemo({this.title = 'Chewie Demo'});
final String title;
@override
State<StatefulWidget> createState() {
return _ChewieDemoState();
}
}
class _ChewieDemoState extends State<ChewieDemo> {
TargetPlatform _platform;
VideoPlayerController _videoPlayerController1;
VideoPlayerController _videoPlayerController2;
ChewieController _chewieController;
@override
void initState() {
super.initState();
_videoPlayerController1 = VideoPlayerController.network(
'https://flutter.github.io/assets-for-api-docs/assets/videos/butterfly.mp4');
_videoPlayerController2 = VideoPlayerController.network(
'https://www.sample-videos.com/video123/mp4/480/asdasdas.mp4');
_chewieController = ChewieController(
videoPlayerController: _videoPlayerController1,aspectRatio: 3 / 2,autoPlay: true,looping: true,// Try playing around with some of these other options:
// showControls: false,// materialProgressColors: ChewieProgressColors(
// playedColor: Colors.red,// handleColor: Colors.blue,// backgroundColor: Colors.grey,// bufferedColor: Colors.lightGreen,// ),// placeholder: Container(
// color: Colors.grey,// autoInitialize: true,);
}
@override
void dispose() {
_videoPlayerController1.dispose();
_videoPlayerController2.dispose();
_chewieController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: widget.title,theme: ThemeData.light().copyWith(
platform: _platform ?? Theme.of(context).platform,),home: Scaffold(
appBar: AppBar(
title: Text(widget.title),body: Column(
children: <Widget>[
Expanded(
child: Center(
child: Chewie(
controller: _chewieController,FlatButton(
onPressed: () {
_chewieController.enterFullScreen();
},child: Text('Fullscreen'),Row(
children: <Widget>[
Expanded(
child: FlatButton(
onPressed: () {
setState(() {
_chewieController.dispose();
_videoPlayerController2.pause();
_videoPlayerController2.seekTo(Duration(seconds: 0));
_chewieController = ChewieController(
videoPlayerController: _videoPlayerController1,);
});
},child: Padding(
child: Text("Video 1"),padding: EdgeInsets.symmetric(vertical: 16.0),Expanded(
child: FlatButton(
onPressed: () {
setState(() {
_chewieController.dispose();
_videoPlayerController1.pause();
_videoPlayerController1.seekTo(Duration(seconds: 0));
_chewieController = ChewieController(
videoPlayerController: _videoPlayerController2,child: Padding(
padding: EdgeInsets.symmetric(vertical: 16.0),child: Text("Error Video"),)
],Row(
children: <Widget>[
Expanded(
child: FlatButton(
onPressed: () {
setState(() {
_platform = TargetPlatform.android;
});
},child: Padding(
child: Text("Android controls"),Expanded(
child: FlatButton(
onPressed: () {
setState(() {
_platform = TargetPlatform.iOS;
});
},child: Text("iOS controls"),)
],);
}
}