Getting ExoPlaybackException while trying to play a video in Flutter

Viewed 31

This is my first time at trying to implement a video player in Flutter. I came across this plugin and it looks good, so thought of giving it a go: https://pub.dev/packages/better_player

However, when I navigate to the video player screen, I see a "Video can't be played, Retry" message appear on the player and receive the following exception in my terminal: [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: PlatformException(VideoError, Video player had error com.google.android.exoplayer2.ExoPlaybackException: Source error, , null)

My Code:

import 'package:better_player/better_player.dart';
import 'package:flutter/material.dart';

class VideoPlayerScreen extends StatefulWidget {
  const VideoPlayerScreen({Key? key}) : super(key: key);

  @override
  State<VideoPlayerScreen> createState() => _VideoPlayerScreenState();
}

class _VideoPlayerScreenState extends State<VideoPlayerScreen> {
  //BetterPlayerConfiguration bpconfig = BetterPlayerCacheConfiguration(asp)
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          AspectRatio(
            aspectRatio: 16 / 9,
            child: BetterPlayer.file("./assets/images/sample_video.mp4"),

            // BetterPlayer.network(
            //   "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4",
            // ),
          ),
        ],
      ),
    );
  }
}

I have tried playing both a network video as well as a file video, but keep on receiving the same error. Since the video url was of the type http, and not https, I even added the following line in my AndroidManifest.xml file, within the <application> tag: android:usesCleartextTraffic="true"

For reference, I followed the following Youtube tutorial to try and implement this: https://www.youtube.com/watch?v=dXxe7E6WPUM&ab_channel=amplifyabhicoding

What is wrong with my code which prevents the videos from playing and how to solve the issue?

0 Answers
Related