vimeo_player
vimeo_player copied to clipboard
How to play video based on dynamic id ?
Video is not playing when I click on listview item, I have passed video id dynamic in VimeoPlayer.
@pradeep-gc Hi! Haven't you tried just using stateful widget as parent? I think it gonna work.
If you're still interested:
Dynamic resource change isn't possible for VideoPlayerController
which is used in vimeo_player
. But you can easily set new controller with another resource. Right now i'm implementing controller
support for this plugin, so later you'll be able to switch resource dynamically. I'll keep in touch when the update comes out.
In my case, I did the following code. The idea here is to use key: UniqueKey() and every time when you select a video from listView the video change
@override
Widget build(BuildContext context) {
return SliverToBoxAdapter(
child: SafeArea(child: Consumer<SeccionesProvider>(
builder: (context, seccionesProvider, _) {
if (seccionesProvider.leccionSeleccionada.tipo != 10) {
return LeccionWidget();
}
return ReproductorWidget(
key: UniqueKey(),
idVideo: seccionesProvider.leccionSeleccionada.idVideo,
);
},
)),
);
}
}
class ReproductorWidget extends StatefulWidget {
final String idVideo;
ReproductorWidget({Key key, @required this.idVideo}) : super(key: key);
@override
_ReproductorWidgetState createState() => _ReproductorWidgetState();
}
class _ReproductorWidgetState extends State<ReproductorWidget> {
@override
Widget build(BuildContext context) {
return Container(
color: MarsaColors.grisOscuro,
child: VimeoPlayer(id: widget.idVideo, autoPlay: true));
}
}```