you tube player flutter
flutter plugin for playing or streaming you tube videos inline using the official iframe player api. supports both android and ios platforms.
salient features
- inline playback
- supports captions
- no need for api key
- supports custom controls
- supports live stream videos
- supports changing playback rate
- support for both android and ios
- adapts to quality as per the bandwidth
- fast forward and rewind on horizontal drag
the plugin uses webview_flutter under-the-hood to play videos.
since webview_flutter relies on flutter’s new mechanism for embedding android and ios views, this plugin might share some known issues tagged with the platform-views and/or webview labels.
setup
ios
opt-in to the embedded views preview by adding a boolean property to the app’s info.plist
file
with the key io.flutter.embedded_views_preview
and the value yes
.
android
no configuration required – the plugin should work out of the box.
using you tube player
youtubeplayer(
context: context,
initialvideoid: "ilnmte5q2qw",
flags: youtubeplayerflags(
autoplay: true,
showvideoprogressindicator: true,
),
videoprogressindicatorcolor: colors.amber,
progresscolors: progresscolors(
playedcolor: colors.amber,
handlecolor: colors.amberaccent,
),
onplayerinitialized: (controller) {
_controller = controller;
_controller.addlistener(listener);
},
),
playing live stream videos
set the islive property to true in order to change the ui to match live video.
youtubeplayer(
context: context,
initialvideoid: "ilnmte5q2qw",
flags: youtubeplayerflags(
islive: true,
),
liveuicolor: colors.amber,
),
want to customize the player?
with v5.x.x and up, use the topactions
and bottomactions
properties to customize the player.
some of the widgets bundled with the plugin are:
- fullscreenbutton
- remainingduration
- currentposition
- playpausebutton
- playbackspeedbutton
- progressbar
youtubeplayer(
context: context,
initialvideoid: "ilnmte5q2qw",
bottomactions: [
currentposition(),
progressbar(isexpanded: true),
totalduration(),
],
),
didn’t like the controls at all?
don’t worry, got a solution for you. 😉
set the hidecontrols property to true, then you can create your own custom controls using the controller obtained from onplayerinitialized property.
youtubeplayer(
context: context,
initialvideoid: "ilnmte5q2qw",
flags: youtubeplayerflags(
hidecontrols: true,
),
onplayerinitialized: (controller) {
//create your own ui using this controller
//on top of the player.
},
),
want to play using you tube urls ?
the plugin also provides converturltoid()
method that converts you tube links to its corresponding video ids.
string videoid;
videoid = youtubeplayer.converturltoid("https://www.youtube.com/watch?v=bbayrbtfsou");
print(videoid); // bbayrbtfsou
example
note
know more about the configuration options here.
download
download apk from above(in badges) and try the plugin.
limitation
since the plugin is based on platform views. this plugin requires android api level 20 or greater.
if you only want to target android and need support for android kitkat or less, then you can use youtube_player.
Comments are closed.