chewie flutter can't play video from youtube - flutter

I try to play video from youtube but I can't play
final controler =
new VideoPlayerController.network("https://youtu.be/0vQWv_EKN6g");
if (!widget.is_audioArea) {
controler.setVolume(0.0);
}
final chewieController = ChewieController(
videoPlayerController: controler,
aspectRatio: 3 / 2,
autoPlay: true,
looping: true,
showControls: false,
);

Related

how to add a youtube video in flutter web

I want to add a Youtube video in my flutter web app , I tried Youtube_player_iframe and its not showing anything ..
here is my code :
void initState() {
super.initState();
_controller = YoutubePlayerController(
params: const YoutubePlayerParams(
showControls: true,
mute: false,
showFullscreenButton: true,
loop: false,
),
)..onInit = (){
_controller.loadVideoByUrl(mediaContentUrl: 'https://www.youtube.com/watch?v=5oZXNRQ0_Uo');
};
}
in the scaffold :
YoutubePlayerControllerProvider(controller: _controller, child: YoutubePlayer(
aspectRatio: 4/3,
controller: _controller,
)),
i found the solution just replace the
_controller.loadVideoByUrl(...);
to
_controller.loadVideo(...);

How to disable rewinding and forwarding the video using Flutter Chewie package?

I am basically trying to prevent the user from rewinding or forwarding the video via progress slider but user should still be able to pause and play the video and see how many seconds/minutes remains till the end of the video.
How can i achieve this using Chewie package in Flutter?
#override
void initState() {
super.initState();
_chewieController = ChewieController(
videoPlayerController: widget.vpController,
aspectRatio: widget.vpController.value.aspectRatio,
autoInitialize: true,
allowFullScreen: true,
allowPlaybackSpeedChanging: false,
deviceOrientationsAfterFullScreen: [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown],
showControls: true,
playbackSpeeds: [1.0],
showOptions: false,
errorBuilder: ((context, errorMessage) {
return Center(
child: Text(errorMessage),
);
})
);
}
you can did it by use customControls property in ChewieController
_chewieController = ChewieController(
videoPlayerController: _videoPlayerController!,
allowFullScreen: false,
showOptions: false,
looping: false,
autoPlay: true,
hideControlsTimer: const Duration(seconds: 1),
customControls: const CustomMaterialControls(
showPlayButton: false,
),
);
in CustomMaterialControls, just clone MaterialControls from chewie and you will see that a function called _buildProgressBar()
Widget _buildProgressBar() {
return Expanded(
child: VideoProgressBar(
controller,
colors: chewieController.materialProgressColors ??
ChewieProgressColors(
playedColor: Theme.of(context).colorScheme.secondary,
handleColor: Theme.of(context).colorScheme.secondary,
bufferedColor: Theme.of(context).backgroundColor.withOpacity(0.5),
backgroundColor: Theme.of(context).disabledColor.withOpacity(.5),
),
handleHeight: 0,
drawShadow: false,
barHeight: 4,
),
);
}
You can disable function onDragStart, onHorizontalDragUpdate in VideoProgressBar then you will get your expectation
onHorizontalDragStart: (DragStartDetails details) {
if (!controller.value.isInitialized|| widget.disableDrag) {
return;
}
}

Flutter better_player Package Stop and Play Video using Controller

I'm new with flutter and currently using better_player: ^0.0.81 package.
Is there anyway to stop the video using a controller? Here is my code below
late BetterPlayerController _betterPlayerController;
Function
_betterPlayerController = BetterPlayerController(
const BetterPlayerConfiguration(
autoPlay: true,
fit: BoxFit.contain,
controlsConfiguration: BetterPlayerControlsConfiguration(
enableOverflowMenu: false,
showControlsOnInitialize: false,
enableRetry: true,
showControls: true,
),
),
betterPlayerDataSource: BetterPlayerDataSource.file(videoPath),
);
Widget
AspectRatio(
aspectRatio: 16 / 9,
child: BetterPlayer(
controller: _betterPlayerController,
),
)
If you mean pause and play, then just call it by using the controller.
eg: _betterPlayerController.pause(); or _betterPlayerController.play();

How to show circular indicator on flutter chewie player on network loss

I am working on a project where I am using flutter chewie player for playing videos. But when there is no network (or when I turned off the internet), it is showing an error as:
VideoError, Video player had error com.google.android.exoplayer2.ExoPlaybackException: Source error, null, null
Instead of this error, I want to show a circular indicator on network loss and want to resume playing when network is restored. How to implement this?
My chewie controller is below:
chewieController = ChewieController(
videoPlayerController: _videoPlayerController,
aspectRatio: 16 / 9,
autoPlay: true,
looping: false,
startAt: Duration(seconds: timeWatched),
errorBuilder: (context, errorMessage) {
return Center(
child: Text(
errorMessage,
style: TextStyle(color: Colors.white),
),
);
},
showControls: true,
allowFullScreen: true,
fullScreenByDefault: false,
customControls: CupertinoControls(
backgroundColor: Colors.black,
iconColor: COLORS['PRIMARY_COLOR'],
));```
You can use connectivity_plus package from pub.dev, and listen to the change in user's device connectivity.
#override
initState() {
super.initState();
subscription = Connectivity().onConnectivityChanged.listen((ConnectivityResult result) {
// Got a new connectivity status!
})
}
You can perform different operations whenever the device connectivity status changes. Like showing CircularProgressIndicator() when status changes to ConnectivityResult.none and resume playing (hide indicator) when status changes to ConnectivityResult.wifi or ConnectivityResult.mobile.
Don't forget to dispose the subscription:
#override
void dispose() {
subscription.cancel();
super.dispose();
}

Can I hide controls on ChewieController at some point in flutter?

I have created a ChewieContoller which looks like this:
_chewieController = ChewieController(
videoPlayerController: widget.videoPlayerController,
aspectRatio: 16/9,
autoInitialize: true,
autoPlay: true,
showOptions: false,
showControls: true,
errorBuilder: (context, errorMessage) {
return Center(
child: Text(
errorMessage,
style: const TextStyle(color: Colors.white),
),
);
},
);
Now showControls is set to true, but at some point I want to change it to false (I want to hide controls). But when I try to do something like this:
_chewieController.showControls = false;
Flutter gives an error saying 'showControls' can't be used as a setter because it's final.
Try finding a different setter, or making 'showControls' non-final.
Is there a way to change showControls propety?
Try creating a new instance with the same videoPlayerController.
_chewieController = ChewieController(
videoPlayerController: _chewieController.videoPlayerController,
aspectRatio: 16/9,
autoInitialize: true,
autoPlay: true,
showOptions: false,
showControls: true,
);