Search code examples
webflutterflutter-web

play video in flutter web


I am trying to create a web app using recently launched flutter_web, but facing issues in playing a video inside my app. Can someone guide me how to play a video in flutter_web.

  1. I tried to create a web plugin for flutter web, but as the official docs of flutter_web we can't create a plugin for web.
  2. I tried to add a video and iframe tag in index.html but no luck.
  3. I tried to use VideoElement provided by dart:html but not sure how to use it.
prefix1.VideoElement element = prefix1.VideoElement();
    element.height = 200;
    element.width = 200;
    element.appendHtml("""<video width="400" controls>
  <source src="mov_bbb.mp4" type="video/mp4">
  <source src="mov_bbb.ogg" type="video/ogg">
  Your browser does not support HTML5 video.
</video>
    """);
    element.querySelector('#video');
    element.play();

Solution

  • You can now just use the official video_player_web plugin by adding it to your pubspec.yaml:

    video_player: ^0.10.4+1
    video_player_web: ^0.1.0
    

    Then you can follow the video player cookbook or use the chewie plugin to get a nice UI.