有什么办法可以在 flutter 项目中使用 libVLC 吗?
Is there any way to use libVLC in flutter project?
我想使用 flutter 和 libVLC 为 android 构建一个视频播放器,以播放存储在设备上的视频。
我该如何实施?
我是 flutter 的新手
您可以使用flutter_vlc_player
先补充一下:
dependencies:
flutter_vlc_player: ^3.0.3
然后像这样使用它:
import 'package:flutter/material.dart';
import 'package:flutter_vlc_player/flutter_vlc_player.dart';
class ExampleVideo extends StatefulWidget {
@override
_ExampleVideoState createState() => _ExampleVideoState();
}
class _ExampleVideoState extends State<ExampleVideo> {
final String urlToStreamVideo = 'http://distribution.bbb3d.renderfarming.net/video/mp4/bbb_sunflower_1080p_60fps_normal.mp4';
final VlcPlayerController controller = new VlcPlayerController(
// Start playing as soon as the video is loaded.
onInit: (){
controller.play();
}
);
final int playerWidth = 640;
final int playerHeight = 360;
@override
Widget build(BuildContext context) {
return Scaffold(
body: SizedBox(
height: playerHeight,
width: playerWidth,
child: new VlcPlayer(
aspectRatio: 16 / 9,
url: urlToStreamVideo,
controller: controller,
placeholder: Center(child: CircularProgressIndicator()),
)
)
);
}
}
使用
flutter_vlc_player 插件
并将url设置为file://${file.path}
您可以使用文件选择器获取文件路径
我想使用 flutter 和 libVLC 为 android 构建一个视频播放器,以播放存储在设备上的视频。 我该如何实施?
我是 flutter 的新手
您可以使用flutter_vlc_player
先补充一下:
dependencies:
flutter_vlc_player: ^3.0.3
然后像这样使用它:
import 'package:flutter/material.dart';
import 'package:flutter_vlc_player/flutter_vlc_player.dart';
class ExampleVideo extends StatefulWidget {
@override
_ExampleVideoState createState() => _ExampleVideoState();
}
class _ExampleVideoState extends State<ExampleVideo> {
final String urlToStreamVideo = 'http://distribution.bbb3d.renderfarming.net/video/mp4/bbb_sunflower_1080p_60fps_normal.mp4';
final VlcPlayerController controller = new VlcPlayerController(
// Start playing as soon as the video is loaded.
onInit: (){
controller.play();
}
);
final int playerWidth = 640;
final int playerHeight = 360;
@override
Widget build(BuildContext context) {
return Scaffold(
body: SizedBox(
height: playerHeight,
width: playerWidth,
child: new VlcPlayer(
aspectRatio: 16 / 9,
url: urlToStreamVideo,
controller: controller,
placeholder: Center(child: CircularProgressIndicator()),
)
)
);
}
}
使用 flutter_vlc_player 插件
并将url设置为file://${file.path}
您可以使用文件选择器获取文件路径