I’m building a Flutter web app that needs to show both Twitch streams and YouTube videos in one place. I got YouTube working fine using different methods, but I’m stuck on the Twitch part.
What I’ve tried so far:
- Used video_player package but it needs direct video URLs
- YouTube works great with youtube_player_flutter package
- Looked into Twitch API but it’s confusing for me
Here’s my current approach using iframe for video display:
class StreamWidget extends StatefulWidget {
final String streamUrl;
StreamWidget(this.streamUrl);
@override
_StreamWidgetState createState() => _StreamWidgetState(streamUrl);
}
class _StreamWidgetState extends State<StreamWidget> {
final String streamUrl;
IFrameElement frameElement = IFrameElement();
_StreamWidgetState(this.streamUrl);
@override
Widget build(BuildContext context) {
frameElement.width = (MediaQuery.of(context).size.width*0.35).toString();
frameElement.height = (MediaQuery.of(context).size.width*0.25).toString();
frameElement.src = "https://www.youtube.com/embed/"+streamUrl;
frameElement.allowFullscreen = true;
ui.platformViewRegistry.registerViewFactory(
'stream'+streamUrl,
(int viewId) => frameElement,
);
return Container(
height: MediaQuery.of(context).size.height * 0.25,
width: MediaQuery.of(context).size.width * 0.35,
decoration: BoxDecoration(
color: Colors.grey[100],
borderRadius: BorderRadius.all(Radius.circular(10))
),
child: HtmlElementView(
key: UniqueKey(),
viewType: 'stream'+streamUrl
),
);
}
}
This iframe method works for embedding Twitch streams, but it shows the entire Twitch interface including chat and other elements. I only want the video player part. Is there a way to display just the stream without all the extra Twitch UI elements?
Any suggestions for a clean solution would be really helpful!