在Flutter中播放Vimeo视频 [英] Playing Vimeo videos in Flutter
问题描述
我正在尝试使用video_player
插件在Flutter应用中播放 vimeo视频,但没有成功,这会引发很多错误.
请帮助我如何在flutter应用程序中实现此功能?使用webview或任何插件等?也许代码片段对我会有很大帮助!
I'm trying to play vimeo videos in flutter app using the video_player
plugin but got no success, it's throwing bunch of errors.
please help me how I might go about implementing this in flutter app? using webview or any plugin etc? perhaps a code snippet would be huge help for me!
这是我的代码段
import 'package:video_player/video_player.dart';
import 'package:flutter/material.dart';
void main() => runApp(VideoApp());
class VideoApp extends StatefulWidget {
@override
_VideoAppState createState() => _VideoAppState();
}
class _VideoAppState extends State<VideoApp> {
VideoPlayerController _controller;
@override
void initState() {
super.initState();
_controller = VideoPlayerController.network(
'https://vimeo.com/{some-video-id}')
..initialize().then((_) {
// Ensure the first frame is shown after the video is initialized, even before the play button has been pressed.
setState(() {});
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Video Demo',
home: Scaffold(
body: Center(
child: _controller.value.initialized
? AspectRatio(
aspectRatio: _controller.value.aspectRatio,
child: VideoPlayer(_controller),
)
: Container(),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
setState(() {
_controller.value.isPlaying
? _controller.pause()
: _controller.play();
});
},
child: Icon(
_controller.value.isPlaying ? Icons.pause : Icons.play_arrow,
),
),
),
);
}
@override
void dispose() {
super.dispose();
_controller.dispose();
}
}
调试控制台中的错误-
E/AccessibilityBridge(28662):VirtualView节点不能是根节点 节点. E/ExoPlayerImplInternal(28662):源错误. E/ExoPlayerImplInternal(28662): com.google.android.exoplayer2.upstream.HttpDataSource $ InvalidResponseCodeException: 响应码:404 E/ExoPlayerImplInternal(28662):at com.google.android.exoplayer2.upstream.DefaultHttpDataSource.open(DefaultHttpDataSource.java:300) E/ExoPlayerImplInternal(28662):在 com.google.android.exoplayer2.upstream.StatsDataSource.open(StatsDataSource.java:83) E/ExoPlayerImplInternal(28662):在 com.google.android.exoplayer2.source.ExtractorMediaPeriod $ ExtractingLoadable.load(ExtractorMediaPeriod.java:885) E/ExoPlayerImplInternal(28662):在 com.google.android.exoplayer2.upstream.Loader $ LoadTask.run(Loader.java:381) E/ExoPlayerImplInternal(28662):在 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) E/ExoPlayerImplInternal(28662):在 java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:641) E/ExoPlayerImplInternal(28662):在 java.lang.Thread.run(Thread.java:919)
E/AccessibilityBridge(28662): VirtualView node must not be the root node. E/ExoPlayerImplInternal(28662): Source error. E/ExoPlayerImplInternal(28662): com.google.android.exoplayer2.upstream.HttpDataSource$InvalidResponseCodeException: Response code: 404 E/ExoPlayerImplInternal(28662): at com.google.android.exoplayer2.upstream.DefaultHttpDataSource.open(DefaultHttpDataSource.java:300) E/ExoPlayerImplInternal(28662): at com.google.android.exoplayer2.upstream.StatsDataSource.open(StatsDataSource.java:83) E/ExoPlayerImplInternal(28662): at com.google.android.exoplayer2.source.ExtractorMediaPeriod$ExtractingLoadable.load(ExtractorMediaPeriod.java:885) E/ExoPlayerImplInternal(28662): at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:381) E/ExoPlayerImplInternal(28662): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) E/ExoPlayerImplInternal(28662): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) E/ExoPlayerImplInternal(28662): at java.lang.Thread.run(Thread.java:919)
推荐答案
您不能使用Vimeo URL https://vimeo.com/{some-video-id} . VideoPlayerController
需要流式视频URL.
You cant use Vimeo URL https://vimeo.com/{some-video-id}. VideoPlayerController
requires the streamable video URL.
解决方案1
Solution 1
Vimeo的必需高级帐户
- 转到 https://vimeo.com/manage/,然后选择要播放的视频
- 从左侧面板中选择分发标签.
- 选择视频文件链接
-
选择播放视频..共付视频链接(其mp4可窃听视频链接)..将此URL用作
VideoPlayerController
.
- go to https://vimeo.com/manage/ and select the video you want to play
- select the distribution tab from the left side panel.
- select video file link
select the play video.. copay the video link(its the mp4 stealable video link)..use this URL for
VideoPlayerController
.
解决方案2
Solution 2
视频链接每15分钟失效
- 调用API https://player.vimeo.com/video/{video_id}/config ,您将获得JSON响应.
- 渐进式对象,您将获得mp4视频网址.
- call the API https://player.vimeo.com/video/{video_id}/config you will get the JSON response.
- progressive object you will get mp4 video url .
解决方案3
Solution 3
- 用
webivew
替换视频控制器,并提供该网址 https://vimeo.com/ {some-video-id} ..启用javascript,视频 将在网络视图中播放.
- Replace the video controller with
webivew
give this url https://vimeo.com/{some-video-id} ..enable the javascript, video will play in webview .
这篇关于在Flutter中播放Vimeo视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!