我需要一种让用户以当前播放速度的1.5-2倍播放我的颤动视频的方法。我已经搜索了video_player文档,因为这是我正在使用的插件,但我找不到解决方法。如何提高播放速度?
答案 0 :(得分:0)
在抖动中,您可以更改视频速度。我没有找到video_player插件的解决方案,但是您可以使用flutter_ijkplayer插件。要以2倍的速度播放视频,可以使用:
controller.setSpeed(2.0);
这是完整的代码:
在pubspec.yaml内部:
flutter_ijkplayer: ^0.3.5+1
在main.dart内部
import 'package:flutter/material.dart';
import 'package:flutter_ijkplayer/flutter_ijkplayer.dart';
void main() {
runApp(new MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MainPage(),
);
}
}
class MainPage extends StatefulWidget {
@override
_MainPageState createState() => _MainPageState();
}
class _MainPageState extends State<MainPage> {
IjkMediaController controller = IjkMediaController();
double speed = 1;
@override
initState() {
super.initState();
setUpResources();
}
Future<void> setUpResources() async {
await controller.setNetworkDataSource(
'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4',
autoPlay: true,
);
await controller.playOrPause();
controller.setSpeed(speed);
print("set data source success");
}
@override
void dispose() {
controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Column(
children: <Widget>[
Container(
// width: MediaQuery.of(context).size.width,
height: 250,
child: IjkPlayer(
mediaController: controller,
),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
RaisedButton(
onPressed: () {
if (speed > 0.25) {
speed = speed - 0.25;
}
setState(() {
controller.setSpeed(speed);
});
},
child: Icon(Icons.indeterminate_check_box),
),
Padding(
padding: const EdgeInsets.all(16.0),
child: Text('$speed'),
),
RaisedButton(
onPressed: () {
speed = speed + 0.25;
setState(() {
controller.setSpeed(speed);
});
},
child: Icon(Icons.add),
),
],
)
],
),
);
}
}