flutter官方的player不适合国内,只能外部解决
推荐一个很不错的,满足国内用户需求的视频播放插件fijkplayer
首先 支持安卓和IOS
其次 支持横屏
然后 支持自定义UI
底层使用ijkplayer
(B站开源的视频库)
看下效果图:
install
dependencies:
fijkplayer: ^0.1.5
例子
import 'package:fijkplayer/fijkplayer.dart';
import 'package:flutter/material.dart';
class VideoScreen extends StatefulWidget {
// final String url;
// VideoScreen({@required this.url});
@override
_VideoScreenState createState() => _VideoScreenState();
}
class _VideoScreenState extends State<VideoScreen> {
final FijkPlayer player = FijkPlayer();
_VideoScreenState();
@override
void initState() {
super.initState();
player.setDataSource("http://192.168.0.130/1007445810_45aec1a65d42425b84c5e14782151d7b_sd.mp4", autoPlay: true);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("Fijkplayer Example")),
body: Container(
child: Column(children: <Widget>[
Container(
width: double.infinity,
height: 200,
child: FijkView(
player: player,
),
),
Text('介绍'),
],),
));
}
@override
void dispose() {
super.dispose();
player.release();
}
}
然后具体看官方文档
fijkplayer.befovy.com/docs/zh/ins…
IOS install
IOS使用就没安卓那么简单了,直接运行会爆如下错误
Error: CocoaPods's specs repository is too out-of-date to satisfy dependencies.
To update the CocoaPods specs, run:
pod repo update
如果直接在当前执行会发现爆如下错误
[!] No `Podfile' found in the project directory.
也就是这玩意不是这样用的,嗯,需要在ios根目录执行,在iOS跟目录下有Podfile
文件,这个是CocoaPods包管理器(IOS包管理器)的配置文件,CocoaPods类似nodejs的npm,类似java的Maven。
执行后可能有如下错误
You have either:
* out-of-date source repos which you can update with `pod repo update` or with `pod install --repo-update`.
* mistyped the name or version.
* not added the source repo that hosts the Podspec to your Podfile.
Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by default.
这时候需要更新pod
pod install --repo-update
然后继续安装我们的ios插件
pod install --verbose
(这时候时间有点长,我等待几十分钟QAQ)
我等了四十几分钟才到98%
然后安装完成
(ios然后在模拟器上面看不了视频,因为这个插件是以纹理的方式渲染,需要用真机)
对于没有ios开发经验的,如何运行在手机上也不是很懂,我等下再写一个跑真机的例子🌰。
--END--