我只是想在我的 iOS 设备上播放从我的 Android 模拟器录制和上传的视频,但由于某种原因,我无法使用 Flutter 中的 VideoContoller 下载它。我想知道这是否与 Android Emulator 上传的视频格式有关,还是我需要将上传的视频转换为不同的格式?现在我从我的 Android 模拟器上传的视频是 MP4 格式的。我也VideoPlayerController.network(widget.url)
用来下载我的文件。
它保持在我的代码片段中指定的旋转:
class VideoPlayerScreen extends StatefulWidget {
String url;
VideoPlayerScreen({Key key, this.url}) : super(key: key);
@override
_VideoPlayerScreenState createState() => _VideoPlayerScreenState();
}
class _VideoPlayerScreenState extends State<VideoPlayerScreen> {
VideoPlayerController _controller;
Future<void> _initializeVideoPlayerFuture;
@override
void initState() {
_controller = VideoPlayerController.network(widget.url);
_initializeVideoPlayerFuture = _controller.initialize();
_controller.setLooping(true);
super.initState();
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Container(
child: Stack(
children: <Widget>[
FutureBuilder(
future: _initializeVideoPlayerFuture,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return AspectRatio(
aspectRatio: _controller.value.aspectRatio,
child: VideoPlayer(_controller),
);
} else {
// If the VideoPlayerController is still initializing, show a
// show spinner.
return Center(child: CircularProgressIndicator());
}
},
),
Center(
child: ButtonTheme(
height: 100.0,
minWidth: 200.0,
child: RaisedButton(
padding: EdgeInsets.all(60.0),
color: Colors.transparent,
textColor: Colors.white,
onPressed: () {
setState(() {
if (_controller.value.isPlaying) {
_controller.pause();
} else {
_controller.play();
}
});
},
child: Icon(
_controller.value.isPlaying
? Icons.pause
: Icons.play_arrow,
size: 120.0,
),
)))
],
),
);
}
}