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(...);
Related
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 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();
}
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,
);
I was using youtube_player_flutter and implemented everything correctly as it was written in it's README.
But still I was facing one issue that whenever I open that page where I want the youtube player to open, it keeps loading and never loads the video.
I've searched about this issue everywhere but didn't get any solution. One of those solutions was that to include internet permission in AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET"/>
I did this, nothing changed. I also downgraded the package to v6.1.1, someone asked me to do this in github issue, but that also did nothing.
How can I resolve this issue?
I'm answering my own question as I didn't find anything that can resolve this problem when I was searching about this issue.
So, I tried to define the controller in initState() and it worked, and now it's working in v7.0.0+7. This is my code:
class AboutTopic extends StatefulWidget {
final String videoLink;
AboutTopic({this.videoLink});
#override
_AboutTopicState createState() => _AboutTopicState();
}
class _AboutTopicState extends State<AboutTopic> {
YoutubePlayerController _controller;
#override
void initState() {
_controller = YoutubePlayerController(
initialVideoId:
YoutubePlayer.convertUrlToId(widget.videoLink),
flags: YoutubePlayerFlags(
mute: false,
autoPlay: true,
disableDragSeek: true,
loop: false,
enableCaption: false),
);
super.initState();
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('About'),
centerTitle: true,
leading: IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () {
Navigator.of(context).pop();
},
)
),
body: YoutubePlayer(
controller: _controller,
showVideoProgressIndicator: true,
bottomActions: <Widget>[
const SizedBox(width: 14.0),
CurrentPosition(),
const SizedBox(width: 8.0),
ProgressBar(isExpanded: true),
RemainingDuration(),
],
aspectRatio: 4 / 3,
progressIndicatorColor: Colors.white,
onReady: () {
print('Player is ready.');
},
),
);
}
}