写一个flutter实例,有视频地址列表和频道列表,使用fijkplayer插件来播放flv视频,点击不同频道切换不同视频地址,一开始就是全屏播放
时间: 2023-05-22 20:00:40 浏览: 179
好的,以下是一个简单的 Flutter 实例,使用 fijkplayer 插件来播放 FLV 视频,并且可以切换不同的视频地址:
```dart
import 'package:flutter/material.dart';
import 'package:fijkplayer/fijkplayer.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Fijkplayer Demo',
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final FijkPlayer player = FijkPlayer();
List<String> channelList = [
'https://example.com/video1.flv',
'https://example.com/video2.flv',
'https://example.com/video3.flv',
];
int currentChannelIndex = 0;
@override
void initState() {
super.initState();
player.setDataSource(channelList[currentChannelIndex], autoPlay: true);
}
@override
void dispose() {
player.release();
super.dispose();
}
void switchChannel(int index) {
setState(() {
currentChannelIndex = index;
});
player.reset();
player.setDataSource(channelList[currentChannelIndex], autoPlay: true);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Flutter Fijkplayer Demo'),
),
body: Column(
children: [
Expanded(
child: FijkView(
player: player,
fit: FijkFit.cover,
),
),
Container(
height: 50,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: channelList.length,
itemBuilder: (context, index) {
return GestureDetector(
onTap: () => switchChannel(index),
child: Container(
padding: EdgeInsets.symmetric(horizontal: 16),
alignment: Alignment.center,
color: currentChannelIndex == index
? Colors.blue
: Colors.grey,
child: Text(
'Channel ${index + 1}',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
),
);
},
),
),
],
),
);
}
}
```
在这个例子中,我们使用了 `FijkPlayer` 来播放 FLV 视频,并且使用了 `FijkView` 来显示视频。我们还使用了一个 `ListView` 来显示频道列表,并且可以点击不同的频道来切换视频地址。
阅读全文