flutter官方的player不適合國內,只能外部解決html
推薦一個很不錯的,知足國內用戶需求的視頻播放插件fijkplayer
java
首先 支持安卓和IOS
其次 支持橫屏
而後 支持自定義UInode
底層使用ijkplayer
(B站開源的視頻庫)ios
看下效果圖: github
dependencies:
fijkplayer: ^0.1.5
複製代碼
例子npm
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();
}
}
複製代碼
而後具體看官方文檔bash
fijkplayer.befovy.com/docs/zh/ins…app
IOS使用就沒安卓那麼簡單了,直接運行會爆以下錯誤ide
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--