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.