dependencies:
fijkplayer: ^0.11.0
import 'package:fijkplayer/fijkplayer.dart';
import 'package:flutter/material.dart';
class RtmpPlayerPage extends StatefulWidget {
const RtmpPlayerPage({super.key});
@override
State createState() => _RtmpPlayerPageState();
}
// ijkplayer参数设置https://www.cnblogs.com/marklove/articles/10608812.html
class _RtmpPlayerPageState extends State {
final FijkPlayer player = new FijkPlayer();
@override
void initState() {
// TODO: implement initState
super.initState();
// 设置这些会降低延迟和打开速度变快
player.setOption(1, "analyzemaxduration", 100);
player.setOption(1, "probesize", 10240);
player.setOption(1, "flush_packets", 1);
player.setOption(4, "packet-buffering", 0);
player.setOption(4, "framedrop", 1);
player.setDataSource("https://live.nodemedia.cn:8443/live/b480_264.flv",
autoPlay: true);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text("Fijkplayer Example")),
body: Container(
alignment: Alignment.center,
child: FijkView(
player: player,
),
));
}
@override
void dispose() {
// TODO: implement dispose
super.dispose();
player.release();
}
}
mediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER,“soundtouch”,isModifyTone?0:1);
mediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_CODEC,“skip_loop_filter”,isSkipLoopFilter?0:48L);
mediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT,“analyzemaxduration”,100L);
mediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT,“analyzeduration”,1);
mediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT,“probesize”,1024*10);
mediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT,“flush_packets”,1L);
mediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER,“packet-buffering”,isBufferCache?1:0);
mediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER,“reconnect”,5);
mediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER,“max-buffer-size”,maxCacheSize);
mediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER,“framedrop”,5);
mediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER,“max-fps”,30);
mediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, “mediacodec”, 1);
mediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, “mediacodec-auto-rotate”, 1);
mediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, “mediacodec-handle-resolution-change”, 1);
某些视频在SeekTo的时候,会跳回到拖动前的位置,这是因为视频的关键帧的问题,通俗一点就是FFMPEG不兼容,视频压缩过于厉害,seek只支持关键帧,出现这个情况就是原始的视频文件中i 帧比较少
mediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, “enable-accurate-seek”, 1);
mediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, “fflags”, “fastseek”);//设置seekTo能够快速seek到指定位置并播放
//某些视频在SeekTo的时候,会跳回到拖动前的位置,这是因为视频的关键帧的问题,通俗一点就是FFMPEG不兼容,视频压缩过于厉害,seek只支持关键帧,出现这个情况就是原始的视频文件中i 帧比较少
mediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, “enable-accurate-seek”, 1);
//播放前的探测Size,默认是1M, 改小一点会出画面更快
mediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, “probesize”, 1024 * 10);