Hi! 👋
Firstly, thanks for your work on this project! 🙂
Today I used patch-package to patch react-native-youtube-iframe@2.4.1 for the project I'm working on.
Here is the diff that solved my problem:
diff --git a/node_modules/react-native-youtube-iframe/lib/commonjs/YoutubeIframe.js b/node_modules/react-native-youtube-iframe/lib/commonjs/YoutubeIframe.js
index 0be2dad..37f7f9d 100644
--- a/node_modules/react-native-youtube-iframe/lib/commonjs/YoutubeIframe.js
+++ b/node_modules/react-native-youtube-iframe/lib/commonjs/YoutubeIframe.js
@@ -55,6 +55,12 @@ const YoutubeIframe = (props, ref) => {
meta
});
webViewRef.current.postMessage(message);
+ if (eventName === 'pauseVideo') {
+ webViewRef.current.injectJavaScript('try{if(window.player&&player.pauseVideo){player.pauseVideo();}}catch(e){} true;');
+ }
+ if (eventName === 'playVideo') {
+ webViewRef.current.injectJavaScript('try{if(window.player&&player.playVideo){player.playVideo();}}catch(e){} true;');
+ }
}, [playerReady]);
(0, _react.useImperativeHandle)(ref, () => ({
getVideoUrl: () => {
diff --git a/node_modules/react-native-youtube-iframe/src/YoutubeIframe.js b/node_modules/react-native-youtube-iframe/src/YoutubeIframe.js
index 4bbf487..ec98015 100644
--- a/node_modules/react-native-youtube-iframe/src/YoutubeIframe.js
+++ b/node_modules/react-native-youtube-iframe/src/YoutubeIframe.js
@@ -63,6 +63,16 @@ const YoutubeIframe = (props, ref) => {
const message = JSON.stringify({eventName, meta});
webViewRef.current.postMessage(message);
+ if (eventName === 'pauseVideo') {
+ webViewRef.current.injectJavaScript(
+ 'try{if(window.player&&player.pauseVideo){player.pauseVideo();}}catch(e){} true;',
+ );
+ }
+ if (eventName === 'playVideo') {
+ webViewRef.current.injectJavaScript(
+ 'try{if(window.player&&player.playVideo){player.playVideo();}}catch(e){} true;',
+ );
+ }
},
[playerReady],
);
This issue body was partially generated by patch-package.
Hi! 👋
Firstly, thanks for your work on this project! 🙂
Today I used patch-package to patch
react-native-youtube-iframe@2.4.1for the project I'm working on.Here is the diff that solved my problem:
This issue body was partially generated by patch-package.