React-native-render-html: Embedded videos not working

Created on 22 Feb 2018  路  12Comments  路  Source: meliorence/react-native-render-html

Ive tried using a webview

alterNode(node) {
const { name, parent } = node;
if(name == 'iframe' ) {
return source={{uri: 'https://www.youtube.com/embed/mUDKuQ8vNf8'}}
style={{height: 100, width: 100}} // OR style={{height: 100, width: 100}}
/>
}
}

im rendering an html string, the idea is to render the iframe's, but just shows a white portion

question

Most helpful comment

Your iframe may have fixed width and height, the following code will eliminate this problem

staticContentMaxWidth={width}
alterChildren={node => {
if (node.name === "iframe" || node.name === "img") {
 delete node.attribs.width;
 delete node.attribs.height;
}
  return node.children;
}}

All 12 comments

Hi,
<iframe> is already being rendered inside a WebView with the default renderer supplied in this plugin. You don't have to use the alteration props to make it work.

Just render an <iframe> with a proper source, and you're done. You might want to make sure it doesn't overflow from your app with the staticContentMaxWidth prop.

When using

const html = '<iframe allowfullscreen="" frameborder="0" height="349" src="https://www.youtube.com/embed/eEupgmLx714" width="560"></iframe>';

It seems like staticContentMaxWidth doesn't work.
"react-native-render-html": "^3.7.0",

EDIT: My bad, introduced in 3.8.X

Tested with 3.10.0 version and staticContentMaxWidth doesn't work with iframe

Your iframe may have fixed width and height, the following code will eliminate this problem

staticContentMaxWidth={width}
alterChildren={node => {
if (node.name === "iframe" || node.name === "img") {
 delete node.attribs.width;
 delete node.attribs.height;
}
  return node.children;
}}

Youtube video still not played, is anyone here can embed youtube video and play it?

@achimbaggins tmtung144 's solution works perfectly for me

@tmtung144 Thanks, dude solution works for me perfectly.

Your iframe may have fixed width and height, the following code will eliminate this problem

staticContentMaxWidth={width}
alterChildren={node => {
if (node.name === "iframe" || node.name === "img") {
 delete node.attribs.width;
 delete node.attribs.height;
}
  return node.children;
}}

You saved my day. Thanks a lot

there is any way to make videos use fullscreen ?

I join the question of @Sadhr does anyone know how to make YouTube videos viewable in full screen on Android?

Still getting crash with iFrame.
@tmtung144 can you plz tell me in which version iFrame dosen't crash in Android.
my react-native-render-html version is 4.2.2

Still getting crash with iFrame

Probably an instance of this react-native-screens bug: https://stackoverflow.com/a/63171413/2779871

does anyone know how to make YouTube videos viewable in full screen on Android?

As for version 5 of react-native-render-html with @native-html/iframe-plugin, you can set allowsFullscreenVideo like so:

import iframe from '@native-html/iframe-plugin';
import HTML from 'react-native-render-html';
import WebView from 'react-native-webview';

const renderers = {
  iframe
}

// ...

<HTML renderers={renderers}
      WebView={WebView}
      source={{ html: '<iframe ...></iframe>' }}
      renderersProps={{ iframe: { webViewProps: { allowsFullscreenVideo: true } }}}
/>
Was this page helpful?
0 / 5 - 0 ratings

Related issues

diamanthaxhimusa picture diamanthaxhimusa  路  7Comments

sayem314 picture sayem314  路  6Comments

gabriel-tentaculo picture gabriel-tentaculo  路  7Comments

sayem314 picture sayem314  路  6Comments

Pradeet picture Pradeet  路  7Comments