I want to create a flutter website where there is a collection of twitch and youtube videos. I tried to use the video_player plugin but for that I can either use the youtube_player plugin or I have to use an API to convert all links to their source files. But I am having trouble making something to embed twitch videos. Anything. Same page with youtube would be perfect but, a seperate twitch player would be good too. Maybe the Twitch API could help but I have no idea how to use it and am unable to understantd it. Here are the plugins I found that may be used\
1>Video_Player
2>Youtube_Player_plugin
Please Help
EDIT
This is the code I am using to make youtube videos with ext_video_player cause it works on web.
class videoBox extends StatefulWidget {
String Video;
videoBox(this.Video);
@override
_videoBoxState createState() => _videoBoxState(Video);
}
class _videoBoxState extends State<videoBox> {
String Video;
bool error = false;
_videoBoxState(this.Video);
VideoPlayerController _controller;
@override
void dispose(){
super.dispose();
_controller.dispose();
}
@override
void initState(){
super.initState();
_controller = VideoPlayerController.network(
Video,
);
_controller.initialize().then((value) {
setState(() {
print("Initialized");
});
});
_controller.addListener(() {
if (_controller.value.hasError) {
print(_controller.value.errorDescription);
setState(() {
error = true;
print(Video);
});
}
});
}
@override
Widget build(BuildContext context) {
return error?Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(15))
),
child: Image(fit:BoxFit.cover,image:NetworkImage("https://hiapseng-thailand.com/wp-content/themes/skywalker/facilities/video-placeholder.jpg"))
):GestureDetector(
onTap:(){
_controller.value.isPlaying?
_controller.pause()
:_controller.play();
},
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(15))
),
child: VideoPlayer(_controller,),
)
);
}
}
EDIT
I figured out a new way to make a video using iFrames. Using this I can add twitch streams but I just want the video, not the whole thing with chat and stuff. How to do that? Here is the coe I am using now
class videoBox extends StatefulWidget {
String Video;
videoBox(this.Video);
@override
_videoBoxState createState() => _videoBoxState(Video);
}
class _videoBoxState extends State<videoBox> {
String Video;
IFrameElement iFrame = IFrameElement();
_videoBoxState(this.Video);
@override
Widget build(BuildContext context) {
iFrame.width = (MediaQuery.of(context).size.width*0.32).toString();
iFrame.height = (MediaQuery.of(context).size.width*0.27).toString();
iFrame.src = "https://www.youtube.com/embed/"+Video;
iFrame.allowFullscreen =true;
// ignore: undefined_prefixed_name
ui.platformViewRegistry.registerViewFactory(
'i'+Video,
(int viewId) =>iFrame,
);
return Container(
height:MediaQuery.of(context).size.height *0.27,
width:MediaQuery.of(context).size.width *0.32,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(15))
),
child: HtmlElementView(
key:UniqueKey(),
viewType:'i'+Video
),
) ;
}
}