@@ -10,7 +10,12 @@ import {View, StyleSheet, Platform} from 'react-native';
1010import WebView from 'react-native-webview' ;
1111import { PLAYER_STATES , PLAYER_ERROR , CUSTOM_USER_AGENT } from './constants' ;
1212import { EventEmitter } from 'events' ;
13- import { MAIN_SCRIPT , PLAYER_FUNCTIONS } from './PlayerScripts' ;
13+ import {
14+ MAIN_SCRIPT ,
15+ PLAYER_FUNCTIONS ,
16+ playMode ,
17+ soundMode ,
18+ } from './PlayerScripts' ;
1419
1520const YoutubeIframe = (
1621 {
@@ -94,23 +99,17 @@ const YoutubeIframe = (
9499 ) ;
95100
96101 useEffect ( ( ) => {
97- if ( playerReady ) {
98- if ( play ) {
99- webViewRef . current . injectJavaScript ( PLAYER_FUNCTIONS . playVideo ) ;
100- } else {
101- webViewRef . current . injectJavaScript ( PLAYER_FUNCTIONS . pauseVideo ) ;
102- }
103-
104- if ( mute ) {
105- webViewRef . current . injectJavaScript ( PLAYER_FUNCTIONS . muteVideo ) ;
106- } else {
107- webViewRef . current . injectJavaScript ( PLAYER_FUNCTIONS . unMuteVideo ) ;
108- }
109- webViewRef . current . injectJavaScript ( PLAYER_FUNCTIONS . setVolume ( volume ) ) ;
110- webViewRef . current . injectJavaScript (
111- PLAYER_FUNCTIONS . setPlaybackRate ( playbackRate ) ,
112- ) ;
102+ if ( ! playerReady ) {
103+ return ;
113104 }
105+
106+ [
107+ playMode [ play ] ,
108+ soundMode [ mute ] ,
109+ PLAYER_FUNCTIONS . setVolume ( volume ) ,
110+ PLAYER_FUNCTIONS . setPlaybackRate ( playbackRate ) ,
111+ ] . forEach ( webViewRef . current . injectJavaScript ) ;
112+
114113 } , [ play , playerReady , mute , volume , playbackRate ] ) ;
115114
116115 const onWebMessage = useCallback (
0 commit comments