0

I'm getting the following error when attempting to parse a video from my backend on my flutter app. The media gets stored in the the temporary location successfully using initial upload codes but fails to fetch it in these particular lines :

VideoPlayerController videocontroller= VideoPlayerController.networkUrl(Uri.parse('http://example.com${video.file}'));
await videocontroller.initialize();
print('${videocontroller.value}');
if (videocontroller.value.duration.inMinutes <= 45) _setPostVideoFile(pickedVideo);
            setState(() {_hasVideo=true;});
          } catch (error) {
            _onError(error);
          }
        

Immediately to check above success, I added a print statement : print('${videocontroller.value}');

And no response comes in. I have added a try-catch error block to catch any other errors other FileTooLarge, HttpieRequestErrorand & HttpieConnectionRefused to be returned as Unknown error. This is the log I see in my console eventually :

I/ExoPlayerImpl(12579): Release ac2febc [ExoPlayerLib/2.18.5] [emu64xa, sdk_gphone_x86_64, Google, 33] [goog.exo.core, goog.exo.exoplayer, goog.exo.decoder, goog.exo.datasource, goog.exo.extractor]    
I/ExoPlayerImpl(12579): Init 9944d57 [ExoPlayerLib/2.18.5] [emu64xa, sdk_gphone_x86_64, Google, 33]
E/ExoPlayerImplInternal(12579): Playback error
E/ExoPlayerImplInternal(12579):   UnknownHostException (no network)
I/flutter (12579): PlatformException(VideoError, Video player had error com.google.android.exoplayer2.ExoPlaybackException: Source error, null, null)
I/flutter (14744): #0      MYSavePostModalState._onError (package:myapp/pages/home/modals/save_post/create_post.dart:850:7)
I/flutter (14744): #1      MYSavePostModalState._getVideoPostActions.<anonymous closure> (package:myapp/pages/home/modals/save_post/create_post.dart:566:13)
I/flutter (12579): <asynchronous suspension>

the 2 dart files referenced in the log are the error blocks for "Unknown error"

I have check the backend api URLs which are in my flutter app and they seem to be fine. The very fact that the video initially uploads to the /media directory part of my backend api shows it is fine.

What I have attempted based on other stack posts with exactly the same error:

<application ...
android:usesCleartextTraffic="true"

Note: Kindly note that my connection is pure http without ssl yet. I wouldn't know if that should be a problem ?

I'm using the following package https://pub.dev/packages/video_player

EDIT: I tried the following :

    final url = Uri.parse('http://www.example.com${video.file}');
                VideoPlayerController videocontroller = VideoPlayerController.networkUrl(url)
                ..initialize().then((value) {  
                // Ensure the first frame is shown after the video is initialized, even before the play button has been pressed.
                setState(() {_hasVideo=true;});
              });
    
                print('${videocontroller.value}');

      if (videocontroller.value.duration.inMinutes <= 45) 
          _setPostVideoFile(pickedVideo);
            setState(() {_hasVideo=true;});
          } catch (error) {
            _onError(error);
          }

I do get the following as I had added a print statement to print the value:

VideoPlayerValue(duration: 0:00:00.000000, size: Size(0.0, 0.0), position: 0:00:00.000000, caption: Caption(number: 0, start: 0:00:00.000000, end: 0:00:00.000000, text: ), captionOffset: 0:00:00.000000, buffered: [], isInitialized: false, isPlaying: false, isLooping: false, isBuffering: false, volume: 1.0, playbackSpeed: 1.0, errorDescription: null)  

That's the only progress I have made until now --> Got to print the value of the video file.

Earthling
  • 83
  • 3
  • 13

1 Answers1

0

Please make sure the following are good in your app:

  • The AndroidManifest.xml file has the internet permissions
<uses-permission android:name="android.permission.INTERNET" />
final url = Uri.parse('http://www.example.com/${video.file}');
  • print the final URI in the console to make sure that we are passing the correct path.
Waseem Abbas
  • 341
  • 1
  • 6
  • Hi. The 1st INTERNET permission was already there. I added / after the url and subsequently printed the url. it shows http://www.example.com//media/media/temporary/4b693e7c-c3a3-473e-906f-9b8884129a40.mp4 – Earthling Jul 18 '23 at 13:27
  • Then you don't need to add `/` after the domain because it's already there. And are you sure that this URL `http://www.example.com/media/media/temporary/4b693e7c-c3a3-473e-906f-9b8884129a40.mp4` is the right path? If you hit this URL in the browser, it should play the video in your browser too. Otherwise, Exoplayer can't play the video if it doesn't play on a browser. – Waseem Abbas Jul 19 '23 at 04:08
  • Just checked. The video does play at the said url. Its after that when i attempt use the url part of networkUrl() and print the value of the video file later , everything shows as zero. Which means thenetworkUrl() and subsequent lines have errors because I added a print statment after the said lines to print the value of the parsed url video file part of networkurl ---> videocontroller.value – Earthling Jul 19 '23 at 05:01