写一个flutter案例。定义两个列表来存放视频地址列表和频道列表,使用chewie插件来播放flv格式的视频,点击不同频道播放不同的视频地址
时间: 2023-05-18 10:05:22 浏览: 297
import 'package:flutter/material.dart';
import 'package:chewie/chewie.dart';
import 'package:video_player/video_player.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Chewie Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Chewie Demo'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
VideoPlayerController _videoPlayerController;
ChewieController _chewieController;
List<String> _videoUrls = [
'https://www.sample-videos.com/video123/flv/720/big_buck_bunny_720p_1mb.flv',
'https://www.sample-videos.com/video123/flv/720/big_buck_bunny_720p_2mb.flv',
'https://www.sample-videos.com/video123/flv/720/big_buck_bunny_720p_5mb.flv',
];
List<String> _channelList = ['Channel 1', 'Channel 2', 'Channel 3'];
int _selectedChannelIndex = 0;
@override
void initState() {
super.initState();
_videoPlayerController = VideoPlayerController.network(_videoUrls[0]);
_chewieController = ChewieController(
videoPlayerController: _videoPlayerController,
autoPlay: true,
looping: true,
);
}
@override
void dispose() {
_videoPlayerController.dispose();
_chewieController.dispose();
super.dispose();
}
void _onChannelSelected(int index) {
setState(() {
_selectedChannelIndex = index;
_videoPlayerController = VideoPlayerController.network(_videoUrls[index]);
_chewieController = ChewieController(
videoPlayerController: _videoPlayerController,
autoPlay: true,
looping: true,
);
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Column(
children: <Widget>[
Expanded(
child: Chewie(
controller: _chewieController,
),
),
SizedBox(height: 16),
Text(
'Channels',
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
),
SizedBox(height: 8),
Container(
height: 50,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: _channelList.length,
itemBuilder: (BuildContext context, int index) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 8),
child: RaisedButton(
color: _selectedChannelIndex == index
? Colors.blue
: Colors.grey,
onPressed: () => _onChannelSelected(index),
child: Text(
_channelList[index],
style: TextStyle(color: Colors.white),
),
),
);
},
),
),
],
),
);
}
}
阅读全文
相关推荐
只需上传附件的文件到服务器,然后在编辑日志的时候加入如下代码:
<script type="text/javascript" src="../Plugins/flv/swfobject.js"></script>
Get the Flash Player to see this player.
<script type="text/javascript">
var s2 = new SWFObject("../Plugins/flv/flvplayer.swf","playlist","480","500","7");
s2.addParam("allowfullscreen","true");
s2.addVariable("file","../Plugins/flv/xml/gougou.xml");
s2.addVariable("displayheight","360");
s2.addVariable("backcolor","0x000000");
s2.addVariable("frontcolor","0xCCCCCC");
s2.addVariable("lightcolor","0x557722");
s2.addVariable("width","480");
s2.addVariable("height","5000");
s2.write("player1");
</script>
里面的的粉色字体改成你所放置的目录。
提交完日志就能得到上面的播放器了。