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.
Related
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.
I have problems with integration of a photography function in my app.
I get asked if I permit the access to the camera, but after that nothing happens exept this errror:
W/Camera (26849): The selected imageFormatGroup is not supported by
Android. Defaulting to yuv420
I/CameraManagerGlobal(26849): Camera 0 facing CAMERA_FACING_BACK state
now CAMERA_STATE_OPEN for client...
This is my code:
class FaultReporting extends StatefulWidget {
#override
_FaultReportingState createState()=> _FaultReportingState();
}
class _FaultReportingState extends State<FaultReporting>{
bool isReady=false;
List<CameraDescription> cameras;
CameraController camController;
#override
void initState() {
super.initState();
setupCameras();
}
Future<void> setupCameras() async {
try {
cameras = await availableCameras();
camController = new CameraController(cameras[0], ResolutionPreset.medium);
await camController.initialize();
} on CameraException catch (_) {
setState(() {
isReady = false;
});
}
setState(() {
isReady = true;
});
}
...
child: ElevatedButton(
onPressed: (){
if(!isReady && !camController.value.isInitialized)
{
return Container();
}
return AspectRatio(
aspectRatio: camController.value.aspectRatio,
child: CameraPreview(camController),
);
},
...
I had the exact same error when I used the camera on flutter. The message is just informing you that the imageFormatGroup parameter must be ImageFormatGroup.yuv420.
So try this:
camController = new CameraController(
cameras[0],
ResolutionPreset.medium,
imageFormatGroup: ImageFormatGroup.yuv420,
);
I had the same issue. However, the abovementioned solution (adding imageFormatGroup: ImageFormatGroup.yuv420) did not solve the problem.
I found out what was the real problem. Turns out Flutter Navigation requires pushed routes to be popped before another one pushed into navigator.
Otherwise, it will cause big issues with all camera using packages (CameraController from camera, QRViewController? controller from qr_code_scanner, MobileScannerController cameraController from mobile_scanner all affected) using packages (Both Android and iOS), specially if you use your own custom internal navigation without using Flutter Navigator.
Because, that way you use Navigator partially and in some situations you push several different routes without popping them or even pushing same route several times.
The camera will come either black or keep loading forever. Only thing will solve the issue is to kill/force stop the app and open again as it clears Flutter Navigator.
In Android you will see this error: "MessageQueue: java.lang.IllegalStateException: Handler sending message to a Handler on a dead thread"
In iOS you will see this: "The selected imageFormatGroup is not supported by iOS. Defaulting to brga8888"
Another related error from mobile_scanner package: flutter: MobileScanner: Called start() while already started!
Realted error from qr_code_scanner package: Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Scan rect cannot be set when not (yet) scanning. You may want to set it within didStartScanningBlock.
Here is the solution which may help you to prevent it. What we need to do is to make sure that when we push new route to the Navigator we are clearing other previously pushed routes from it:
For undefined routes:
Navigator.of(context).pushAndRemoveUntil(
MaterialPageRoute(
builder: (context) => YourPage()),
(Route<dynamic> route) => false);
For defined routes:
Navigator.of(context)
.pushNamedAndRemoveUntil('/yourdefinedroute', (Route<dynamic> route) => false);
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),
),
);
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
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.