Not getting the error in Video Player in flutter? - flutter

I am using the video_player package provided by flutter team to implement a video player in my flutter project. Everything is working fine when internet is connected. But the problem with me is I could not get the error while turning off my internet and also when I am providing wrong video url to the video player controller. Below is my code:-
videoPlayerController = VideoPlayerController.network(alertClipList[0]);
videoPlayerController.addListener(() {
print('here');
if(videoPlayerController.value.isBuffering){
print('buffering');
}else if(videoPlayerController.value.hasError){
print('error');
}else if(videoPlayerController.value.position == videoPlayerController.value.duration){
print('completed');
}
});
var temp = await videoPlayerController.initialize().then((value){
print('started');
if(videoPlayerController.value.isPlaying){
print('already playing');
return;
}
videoPlayerController.play();
}, onError: (error){
print(error);
print('error is here');
});
And here is the simple UI code:
Widget JVideoPlayer() {
return AspectRatio(
aspectRatio: 16 / 9,
child: VideoPlayer(alertClipController.videoPlayerController));
}
Also I using the below implementation of exoplayer
implementation 'com.google.android.exoplayer:exoplayer:2.16.1'

I solved the issue by removing this line from my app level build.gradle file - implementation 'com.google.android.exoplayer:exoplayer:2.16.1'. I think there is no problem with the video player package, the problem is with the exoplayer.

Related

How to identify if the controls has gone or not in flutter chewie video player

I am working on a flutter app and using chewie videoplayer plugin.So when we started playing a video it shows controls at bottom and after few seconds it vanishes and when we move the mouse again it shows again. so is there any method to find when the controls are shown on screen and when its not shown.
actually i am giving close button on the video player. but it doesnt vanishes with those video player controls. it still stay on screen so to hide that close button along with video controls i need to get which process hides the control.
Please help me...
This process is inside the source code of chewie player. So if you need to customize and synchronise your own custom controls and options, either you have to explicitly fetch the source code and edit in that or you need to make your own controllers from scratch using video_player package as the core.
You need to customize the source code of the chewie player.
You can find MaterialControl class inside the source code of this package there is a function called _buildHitArea() just change notifier.hideStuff boolean according to your preference.
Widget _buildHitArea() {
final bool isFinished = _latestValue.position >= _latestValue.duration;
final bool showPlayButton = widget.showPlayButton && !_dragging && !notifier.hideStuff;
return GestureDetector(
onTap: () {
if (_latestValue.isPlaying) {
if (_displayTapped) {
setState(() {
notifier.hideStuff = false;
});
} else {
_cancelAndRestartTimer();
}
} else {
_playPause();
setState(() {
notifier.hideStuff = false;
});
}
},
child: CenterPlayButton(
backgroundColor: Colors.black54,
iconColor: Colors.white,
isFinished: isFinished,
isPlaying: controller.value.isPlaying,
show: showPlayButton,
onPressed: _playPause,
),
);
}

Flutter video_player sound sometimes not in sync with video

I am having an issue with Flutter video_player where sometimes the video hangs and the sound is not in sync with the video. There is a delay of ~1 second between the video and sound. This only happens when playing certain videos, most videos are fine. I've checked that one of the affected videos is in the same format (mp4) as other videos and also have downloaded that video from my S3 bucket and have confirmed that it plays correctly in that case, so I believe it must be an issue with the video_player plugin. Here is my code to load the video controller. Is there any reason that videos would behave differently with this plugin where the audio and video are not in sync?
void loadVideo() async {
videoController =
VideoPlayerController.network(videoLink);
videoController.initialize().then((_) {
if (!mounted) {
// displays an error message if the video controller doesn't load
videoError = true;
setState(() {});
return;
}
setState(() {});
});
videoController.addListener(_listenForError);
}
void playVideo() async {
videoController.play();
}
Widget cameraWidget = Transform.scale(
scale: videoController.value.aspectRatio / deviceRatio,
child: AspectRatio(
aspectRatio: videoController.value.aspectRatio,
child: VideoPlayer(videoController),
),
);

Flutter Flick video player not playing device's videos

I was using flick video player package in flutter but it works on network videos & not on device videos, even though path stated is correct.
Error message:
Unexpected error1: 'package:flutter/src/services/message_codec.dart':
Failed assertion: line 111 pos 15: 'code != null': is not true.
Code:
#override
void initState() {
secure();
print(widget.video.path);
super.initState();
flickManager = FlickManager(
videoPlayerController: widget.video != null
? VideoPlayerController.network(widget.videoLink)
: VideoPlayerController.file(
File("/storage/emulated/0/Download/K2app/1603884177002/no.mp4"))
..addListener(() {
print("added");
setState(() {});
})
..initialize().then((value) {
print('initialized listener');
setState(() {});
}).catchError((error) {
print('Unexpected error1: $error');
}));
}
If you are running it on the web, then this is still an open issue.
The Web platform does not support dart:io, so attempts to create a VideoPlayerController.file will throw an UnimplementedError.
Please check this below link.
https://pub.dev/packages/video_player_web
I tried with your code snippet on android device and I was able to play video.
Although, when I tried to play a .mov video format it ran in some exception.
I see you are trying to play a .mp4 video , can you try with the latest version, flick_video_player: ^0.3.1 and check if you are still getting this error.

Playing videos with flutter web and firebase storage

I am trying to make a website in which the user can add videos and also see these videos. All of them are stored in firebase storage. This is how I store it
fb.StorageReference storageRef = fb.storage().ref('videos/$chapter)');
fb.UploadTaskSnapshot uploadTaskSnapshot = await storageRef.put(videoFile, fb.UploadMetadata(contentType: 'video/mp4')).future;
await uploadTaskSnapshot.ref.getDownloadURL().then((value){
videoUrl = value.toString();
});
snapshot.reference.collection("videos").add({
"chapter":chapter,
"class":grade,
"description":description,
"notes":notes,
"subject":subject,
"video":videoUrl,
"timestamp":DateTime.now().millisecondsSinceEpoch.toString()
});
And I play them using the normal video player plugin. Now the problem is when I store it, I get a url like
https://firebasestorage.googleapis.com/v0/b/studyme-me.appspot.com/o/videos%2Ff)?alt=media&token=ec4fea39-032b-438f-8122-f8e042c1c9c7
But the video player in flutter web requires a .mp4 or .wav or something like that file. What can I do that can either allow the video player to play these (I don't think its possible) or I can get the .mp4 file for this. Maybe I can use firebase storage to open this url and get it but I dont know how
Any suggestions would be appreciated
You can use the VideoPlayerController plugin to do that
VideoPlayerController controller = VideoPlayerController.network('your-video-url',);
//Play/Pause Video:
FloatingActionButton(
onPressed: () {
// Wrap the play or pause in a call to `setState`. This ensures the
// correct icon is shown
setState(() {
// If the video is playing, pause it.
if (_controller.value.isPlaying) {
_controller.pause();
} else {
// If the video is paused, play it.
_controller.play();
}
});
},
// Display the correct icon depending on the state of the player.
child: Icon(
_controller.value.isPlaying ? Icons.pause : Icons.play_arrow,
),
)
'''
more examples in the link above

How to fix MissingPluginException on Agora video call?

I'm building an App which can make Video calls, I'm using Agora SDK for the feature. I'm having a problem when I want to run the app on my device. Naturally it would ask for Camera and Microphone permission but it doesn't ask me and the video call feature won't start. Here's some of my code:
The Function that gives me the error
Future<void> onJoin() async {
// update input validation
setState(() {
_channelController.text.isEmpty
? _validateError = true
: _validateError = false;
});
if (_channelController.text.isNotEmpty) {
// await for camera and mic permissions before pushing video page
await _handleCameraAndMic(); // doesn't asks for any permissions so the video call won't start
//await _permissions();
// push video page with given channel name
await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => CallPage(
channelName: _channelController.text,
),
),
);
}
}
Future<void> _handleCameraAndMic() async {
await PermissionHandler().requestPermissions(
[PermissionGroup.camera, PermissionGroup.microphone],
);
}
The Exception I'm getting
Unhandled Exception: MissingPluginException(No implementation found
for method requestPermissions on channel
flutter.baseflow.com/permissions/methods)
I'm using this as a reference for bulding the feature
I'm not sure where did I do wrong because I'm very new to flutter development. Any help would be appreciated and if you need more code I will provide it to you, just feel free to ask. Thank you.
There is an open issue on their repo, see this.
Probably the plugin is buggy, so you may try some other plugin.