Replies: 3 comments
-
So you have 3 different ways to render a YouTube player from HTML?
The Do you want to use your custom player or the web view widget? |
Beta Was this translation helpful? Give feedback.
-
Well I have #2 or #3. I am trying to get everything into #1 so it will work with your built in webview iframe YouTube player. I could pre-parse my html to get #2/3 into #1, but I'd rather do the parsing within |
Beta Was this translation helpful? Give feedback.
-
Yeah, using mixin _YouTubeLink on WidgetFactory {
@override
void parse(BuildMetadata meta) {
final e = meta.element;
if (e.localName == 'a') {
final href = e.attributes['href'];
if (href?.contains('youtube.com/embed') == true) {
meta.register(BuildOp(
onWidgets: (context, widgets) {
return [buildWebView(meta, href)];
},
));
return;
}
}
super.parse(meta);
}
} The plain text is also possible but harder because you need to look into each DOM element and extract the embed link from there. Which is slow and error prone. It's probably easier if you have your own |
Beta Was this translation helpful? Give feedback.
-
My YouTube urls in my HTML string are usually as follows
OR
I was previously successfully using a
BuildOp
to create a custom YouTube widget by regexing for YouTube urls inside.parse
.Now I've switched from
flutter_widget_from_html_core
toflutter_widget_from_html
and am using your YouTube parser, but I need to get my YouTube video into a properiframe
format by parsing the html.It looks like the
.parse
is happening after your YouTube parser.When I put in the below code into
.parse
, which I previously used successfully as part of aBuildOp
, the raw text HTML<iframe src="https://www.youtube.com/embed/..." allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"></iframe>
shows up in the final output rather then a YouTube video.I can get it to work by pre parsing the HTML before I even send it to
HtmlWidget
but Id rather parse it inside the widget itself so I can take advantage of the tree structure as my YouTube URLs are sometimes sitting inside<a></a>
and sometimes not. Its also cleaner for me to do it insideHtmlWidget
since I am using the widget in multiple places in my appBeta Was this translation helpful? Give feedback.
All reactions