PlatformException(VideoError, Video player had error com.google.android.exoplayer2.ExoPlaybackException: Source error, null, null)
Asked Answered
T

13

22

**HI I am trying to play a live news video in my flutter app it is .m3u8 format but get above error. Using all of the updated dependencies. I want to play live news in my flutter app. I have the url you can also try it. URL: http://161.97.162.167:1936/live/tnnnews/playlist.m3u8 When I use another url with .m3u8 it plays on flutter app but when I paste the live url code it throws me the above error. **

Code

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


class VideoApp extends StatefulWidget {
  @override
  _VideoAppState createState() => _VideoAppState();
}

class _VideoAppState extends State<VideoApp> {
  VideoPlayerController _controller;

  @override
  void initState() {
    super.initState();
    _controller = VideoPlayerController.network(
        'http://161.97.162.167:1936/live/tnnnews/playlist.m3u8')
      ..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.isInitialized
              ? 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();
  }
}
Tani answered 1/8, 2021 at 7:33 Comment(3)
On which device you're testing?Philipphilipa
Testing on Nokia 6.1 plusTani
This issue is still open since May, 2021 on github.com/flutter/flutter/issues/81804 . Still without a final solution.Jennifer
Y
9

Put this in your AndroidManifest.xml

<application ...
android:usesCleartextTraffic="true"
Yearbook answered 8/2, 2022 at 20:59 Comment(1)
My AndroidManifest.xml already have this line and it's not workingHaith
S
6

This issue happened with me and after searching I found the issue is in link itself As the library will only work if the extension of your link is .mp4 and if not you have to parse it to contain the .mp4 extension

Soerabaja answered 21/4, 2022 at 21:6 Comment(1)
flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4 this is a mp4Joyajoyan
B
3

Hey i got the same error today in 2022/19/8 .Just adding fijkplayer: ^0.10.0 in your project pubsec.yaml file it would work then.

Boyes answered 19/8, 2022 at 14:23 Comment(2)
DONT do this this ruined my Gradle build .. don't know what To do from here isn't google going to fix this issue?Zollie
Im sorry for the inconvenience but I got sorted with this.Boyes
M
3

having the same problem I solved it by adding the exoplayer implementation to the app/build.gradle and you have to hit sync, code:

dependencies {
    implementation('com.google.android.exoplayer:exoplayer:2.19.1')
}

hope it helps

Mulhouse answered 20/12, 2023 at 19:56 Comment(0)
T
1

My AndroidManifest.xml already have this line and it's not working. So, the issue is in link. After link you have to add extension like .mp4 It is working for me.

Terribly answered 3/12, 2022 at 7:5 Comment(0)
A
1

I know this is pretty late, but to anyone who is still struggling in 2023 because of this disastrous bug, which you'd probably run into upon changing the videos in your flutter app running on physical devices. Calling the following code (onControllerChange method) can help you get rid of it when you are changing your video (loading next or previous video). You have to dispose and create (initialize) the controller every time you change the video

Future <void> onControllerChange () async {
                    if (_videoPlayerController == null) { //if current controller is null
                      initializeController(); //method to initialize your video controller
                    } else {
                      final oldController = _videoPlayerController;
                      await oldController.dispose();
                      initializeController();
                    }
}

    
late VideoPlayerController _videoPlayerController;
initializeController () {
            _videoPlayerController = VideoPlayerController.network(
                    'your video url')
                  ..initialize().then((_) {
                    setState(() {}); //here you could use Provider or any other state management approach. I use bloc
                  });
}
    

 
Ain answered 15/5, 2023 at 21:45 Comment(3)
This code has no meaning. and this is also not working for me!Volpe
The code implies that you have to dispose the old video controller and create a new one when you change the videoAin
I edited the code. Perhaps it'd be helpful nowAin
P
0

Perform a Flutter clean and run the application .

Pansy answered 15/8, 2022 at 13:42 Comment(1)
you can also add some code sample for better ansewerBinette
D
0

I got this error using an MP4 video stored in the project assets. To solve the problem I decreased the dimensions of the video from 2160x4096 to 1080x2048.

Doorframe answered 29/12, 2022 at 13:40 Comment(0)
P
0

For me this solves the problem:

controller = VideoPlayerController.asset(widget.video)
  ..initialize().then((value) {
    setState(() {
      controller.play();
    });
  });
Perfume answered 12/1, 2023 at 5:39 Comment(0)
L
0

if you have already added android:usesCleartextTraffic="true" in your manifest application tag. just uninstall the build completely and install new one. that fixed in my case.

Loiseloiter answered 14/8, 2023 at 8:1 Comment(0)
H
0

I have the same issue while using the video_player flutter package video_player: ^2.6.0

and the error is

Error: - flutter: PlatformException(VideoError, Failed to load video: The file couldn’t be opened because you don’t have permission to view it., null, null)

I gave all the permission and my flutter is also set perfectly and working perfectly

Solution:- So I restarted my iPhone 8 device and then opened my app and everything worked fine no exceptions no bugs nothing else

UseCase: - maybe it was caused by multiple requests to access files at a time

Heterochromatic answered 29/11, 2023 at 12:1 Comment(1)
any other solution?Heterochromatic
B
-1

I've done this and it worked for me

  • uninstall the app
  • run flutter clean
  • run flutter pub get
  • run your application again
Billowy answered 8/9, 2022 at 9:22 Comment(0)
U
-2

Video url should be started with https not http.

video_player package doesn't support the video which starts with http.

Unread answered 25/1, 2023 at 12:34 Comment(1)
This is not true. It supports both URLsUlpian

© 2022 - 2024 — McMap. All rights reserved.