在Flutter中播放Vimeo视频 [英] Playing Vimeo videos in Flutter

查看:182
本文介绍了在Flutter中播放Vimeo视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用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的必需高级帐户

  1. 转到 https://vimeo.com/manage/,然后选择要播放的视频
  2. 从左侧面板中选择分发标签.
  3. 选择视频文件链接
  4. 选择播放视频..共付视频链接(其mp4可窃听视频链接)..将此URL用作VideoPlayerController.

  1. go to https://vimeo.com/manage/ and select the video you want to play
  2. select the distribution tab from the left side panel.
  3. select video file link
  4. select the play video.. copay the video link(its the mp4 stealable video link)..use this URL for VideoPlayerController.

解决方案2

Solution 2

视频链接每15分钟失效

  1. 调用API https://player.vimeo.com/video/{video_id}/config ,您将获得JSON响应.
  2. 渐进式对象,您将获得mp4视频网址.
  1. call the API https://player.vimeo.com/video/{video_id}/config you will get the JSON response.
  2. progressive object you will get mp4 video url .

解决方案3

Solution 3

  1. webivew替换视频控制器,并提供该网址 https://vimeo.com/ {some-video-id} ..启用javascript,视频 将在网络视图中播放.
  1. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆