视频播放器颤振的基本界面
Posted
技术标签:
【中文标题】视频播放器颤振的基本界面【英文标题】:Basic interface for video player flutter 【发布时间】:2020-12-04 03:47:03 【问题描述】:我正在使用这个库来实现视频功能。
https://pub.dev/packages/video_player
目前,我已经成功地让它工作了。
但是,接下来,我需要通过代码制作播放/暂停或搜索按钮??
我想要的只是简单的控制器,比如OS基本播放器,没有可设计的就可以了。
我想有一种方法可以更轻松地实现接口,而无需重新发明***......
我说的对吗?
我四处搜索,但找不到。
【问题讨论】:
【参考方案1】:你可以使用包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,
aspectRatio: 3 / 2,
autoPlay: true,
looping: true,
);
);
,
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,
aspectRatio: 3 / 2,
autoPlay: true,
looping: true,
);
);
,
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"),
padding: EdgeInsets.symmetric(vertical: 16.0),
),
),
),
Expanded(
child: FlatButton(
onPressed: ()
setState(()
_platform = TargetPlatform.ios;
);
,
child: Padding(
padding: EdgeInsets.symmetric(vertical: 16.0),
child: Text("iOS controls"),
),
),
)
],
)
],
),
),
);
【讨论】:
谢谢!!这对我来说是完美的解决方案!以上是关于视频播放器颤振的基本界面的主要内容,如果未能解决你的问题,请参考以下文章
如何将桌面(macOS 和 Windows)的视频播放器添加到颤振中