Skip to content

Instantly share code, notes, and snippets.

@littleironical
Created December 2, 2020 09:35
Show Gist options
  • Save littleironical/258f1ce9c1ebbb5a7a3dc1dd8b04b604 to your computer and use it in GitHub Desktop.
Save littleironical/258f1ce9c1ebbb5a7a3dc1dd8b04b604 to your computer and use it in GitHub Desktop.
//Have to define the _controller inside initState() to make it work properly.
//Inside StateFulClass:
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(
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.');
},
),
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment