11

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!

here is my code snippet

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();
  }
}

THE ERROR IN DEBUG CONSOLE -

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)

Kunu
  • 5,078
  • 6
  • 33
  • 61
Teekam Suthar
  • 529
  • 1
  • 9
  • 20
  • Please, provide code example that explain what you try to do. – Abjox Feb 28 '20 at 12:39
  • @Abjox i've updated my question, please have a look at it. Thank you so much for your help! – Teekam Suthar Feb 28 '20 at 13:12
  • The video_player plugin is for playing video files directly, which means you need a direct URL to the video file itself. You aren't going to be able to just give it the URL of some random site where a video happens to be on the page somewhere, because it won't know what to do with that. – Abion47 Feb 28 '20 at 14:55
  • thanks for your response @Abion47 is there any other way to achieve this? – Teekam Suthar Feb 29 '20 at 13:18
  • I'm deeply in need to integrate vimeo in my flutter app, please let me know if it can be achieved or not? – Teekam Suthar Feb 29 '20 at 13:19
  • There aren't any plugins for Vimeo videos that I can find so your only option is probably to use a web view to embed the video player into. – Abion47 Feb 29 '20 at 15:55
  • thanks @Abion47, can you please provide me with any example on how to use webview to embed vimeo? i'm a newbie to flutter, it would be a huge help for me. thanks again! – Teekam Suthar Mar 01 '20 at 10:28

3 Answers3

28

You cant use Vimeo URL https://vimeo.com/{some-video-id}. VideoPlayerController requires the streamable video URL.

Solution 1

Required premium account of Vimeo

  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.

    enter image description here

Solution 2

Video link will expire in every 15 mins

  1. call the API https://player.vimeo.com/video/{video_id}/config you will get the JSON response. enter image description here
  2. progressive object you will get mp4 video url .

Solution 3

  1. Replace the video controller with webivew give this url https://vimeo.com/{some-video-id} ..enable the javascript, video will play in webview .
Rahul Devanavar
  • 3,917
  • 4
  • 32
  • 61
  • 3
    I have created a test version of a vimeo player. Feel free to fork and modify! https://github.com/ThuAbLKA/flutter-vimeo-player – thusith.92 Apr 24 '20 at 03:13
  • @Rahul Devanavar I am using Solution 1: PRO members have access to direct video file links. As is know Vimeo does not support, nor recommend using URLs. Do they change URLs without any prior notification even for PRO members? – Jyo Oct 12 '20 at 03:36
  • Thank you, trying the second solution but the config API is not responding to private videos even with private links, any workaround Thanks again – Galeb Nassri Dec 01 '20 at 21:53
  • is there any option available to play private Vimeo video? – Jithin Joy Mar 12 '21 at 06:39
  • Yes you can use config api – Rahul Devanavar Mar 12 '21 at 18:54
0

Install vimeoplayer: ^0.1.8 on pubspec

return Scaffold(
        appBar: AppBar(title: Text('Video EasyRider')),
       body: ListView(children: <Widget>[
          VimeoPlayer(id: '123456789', autoPlay: false),
        ]));
  }
David Buck
  • 3,752
  • 35
  • 31
  • 35
0

You can use vimeo_player_flutter package to achieve this. It is easy & supports Android and IOS platforms. It works based on webview.

Refer this link for more details on this.

ritsapp
  • 80
  • 2
  • 1
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/31563168) – K.Mat Apr 21 '22 at 12:25