Play local videos in Flutter

Issue

I need to play a asset video in my app but the vide player plugin keeps on buffering but didn’t play the video. But if I use network videos then the code works perfectly.

Here is my code,

class LandscapePlayer extends StatefulWidget {
  @override
  _LandscapePlayerState createState() => _LandscapePlayerState();
}

class _LandscapePlayerState extends State<LandscapePlayer> {
  FlickManager flickManager;

  @override
  void initState() {
    super.initState();
    flickManager = FlickManager(videoPlayerController:
         VideoPlayerController.asset('videos/first.mp4',),);
  }

  @override
  void dispose() {
    flickManager.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: FlickVideoPlayer(
        flickManager: flickManager,
        preferredDeviceOrientation: [
          DeviceOrientation.landscapeRight,
          DeviceOrientation.landscapeLeft
        ],
        systemUIOverlay: [],
        flickVideoWithControls: FlickVideoWithControls(
          controls: LandscapePlayerControls(),
        ),
      ),
    );
  }
}

I have added the video file as a dependency in pubspec.yaml file. I don’t know why it works for network files but not for asset file.

Solution

I solved this issue. video_player plugin uses Exo player plugin in android which is not working correctly in some devices(due to decoders or something). An easy alternative is to go by native_video_view plugin.

Answered By – Gowthamaan Ravi

Answer Checked By – David Marino (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published.