flutter用chewie播放flv格式的视频示例
时间: 2023-05-19 12:02:52 浏览: 286
以下是一个使用 Chewie 播放 FLV 格式视频的 Flutter 示例代码:
```dart
import 'package:flutter/material.dart';
import 'package:chewie/chewie.dart';
import 'package:video_player/video_player.dart';
class FLVPlayer extends StatefulWidget {
final String videoUrl;
FLVPlayer({@required this.videoUrl});
@override
_FLVPlayerState createState() => _FLVPlayerState();
}
class _FLVPlayerState extends State<FLVPlayer> {
VideoPlayerController _videoPlayerController;
ChewieController _chewieController;
@override
void initState() {
super.initState();
_videoPlayerController = VideoPlayerController.network(widget.videoUrl);
_chewieController = ChewieController(
videoPlayerController: _videoPlayerController,
aspectRatio: 16 / 9,
autoPlay: true,
looping: true,
);
}
@override
void dispose() {
_videoPlayerController.dispose();
_chewieController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('FLV Player'),
),
body: Center(
child: Chewie(
controller: _chewieController,
),
),
);
}
}
```
你可以在 `FLVPlayer` 类中传入一个 FLV 格式视频的 URL,然后使用 `Chewie` 组件来播放视频。注意,你需要在 `initState` 方法中初始化 `VideoPlayerController` 和 `ChewieController`,并在 `dispose` 方法中释放资源。
阅读全文