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,
);
Related
I have 2 screens. Screen A is the settings screen where I change the axis (horizontal/vertical). Change the axis in the carousel slider, which is on screen B.
I wrote a method that handles the toggle button, but I don't understand how I can get the necessary changes on screen B.
Screen A:
class _ChooseSettingsScreenState extends State<ChooseSettingsScreen> {
bool swipeTrue = true;//vertical
#override
Widget build(BuildContext context) {
...
GFToggle(
onChanged: (swipeTrue){
mySwipeHandler(context);
},
value: false,
type: GFToggleType.ios,
enabledTrackColor: Colors.black26,
disabledTrackColor: Colors.white70,
enabledThumbColor: Colors.blueAccent,
disabledThumbColor: Colors.blueAccent,
)
...
Axis mySwipeHandler (BuildContext context) {
if (swipeTrue == true){
setState(() {
swipeTrue = false;
});
print("chose vertical");
return Axis.vertical;
} else {
setState(() {
swipeTrue = true;
});
print("chose horizontal");
return Axis.horizontal;
}
}
...
Screen B:
child: CarouselSlider.builder(
itemCount: quoteList.length,//Changed
options: CarouselOptions(
viewportFraction: 1.0,
pageSnapping: true,
reverse: false,
initialPage: 0,
scrollDirection: Axis.horizontal,
onPageChanged: (index, value){
HapticFeedback.lightImpact();
setState((){});
}
),
I need to change Axis.horizontal to Axis.vertical and back via toggle button (Screen A)
Help me please friends!
You can make condition like this:
Define swipeTrue variable global:
child: CarouselSlider.builder(
itemCount: quoteList.length,//Changed
options: CarouselOptions(
viewportFraction: 1.0,
pageSnapping: true,
reverse: false,
initialPage: 0,
scrollDirection: swipeTrue==true?Axis.vertical : Axis.horizontal,
onPageChanged: (index, value){
HapticFeedback.lightImpact();
setState((){});
}
),
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(...);
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;
}
}
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();
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,
);