@@ -6,9 +6,9 @@ import React, {
66 forwardRef ,
77 useState ,
88} from 'react' ;
9- import { View , StyleSheet } from 'react-native' ;
9+ import { View , StyleSheet , Platform } from 'react-native' ;
1010import WebView from 'react-native-webview' ;
11- import { PLAYER_STATES , PLAYER_ERROR } from './constants' ;
11+ import { PLAYER_STATES , PLAYER_ERROR , CUSTOM_USER_AGENT } from './constants' ;
1212import { EventEmitter } from 'events' ;
1313import { MAIN_SCRIPT , PLAYER_FUNCTIONS } from './PlayerScripts' ;
1414
@@ -18,19 +18,20 @@ const YoutubeIframe = (
1818 width,
1919 videoId,
2020 playList,
21- playListStartIndex = 0 ,
2221 play = false ,
23- onChangeState = _event => { } ,
24- onReady = _event => { } ,
25- onError = _err => { } ,
26- onPlaybackQualityChange = _quality => { } ,
2722 mute = false ,
2823 volume = 100 ,
29- playbackRate = 1 ,
30- onPlaybackRateChange = _playbackRate => { } ,
31- initialPlayerParams = { } ,
3224 webViewStyle,
3325 webViewProps,
26+ playbackRate = 1 ,
27+ onError = _err => { } ,
28+ onReady = _event => { } ,
29+ playListStartIndex = 0 ,
30+ initialPlayerParams = { } ,
31+ forceAndroidAutoplay = false ,
32+ onChangeState = _event => { } ,
33+ onPlaybackQualityChange = _quality => { } ,
34+ onPlaybackRateChange = _playbackRate => { } ,
3435 } ,
3536 ref ,
3637) => {
@@ -163,13 +164,22 @@ const YoutubeIframe = (
163164 return (
164165 < View style = { { height, width} } >
165166 < WebView
166- style = { [ styles . webView , webViewStyle ] }
167167 ref = { webViewRef }
168168 originWhitelist = { [ '*' ] }
169- source = { { html : MAIN_SCRIPT ( videoId , playList , initialPlayerParams ) } }
170- mediaPlaybackRequiresUserAction = { false }
171- allowsInlineMediaPlayback
172169 onMessage = { onWebMessage }
170+ allowsInlineMediaPlayback
171+ style = { [ styles . webView , webViewStyle ] }
172+ mediaPlaybackRequiresUserAction = { false }
173+ allowsFullscreenVideo = { ! initialPlayerParams ?. preventFullScreen }
174+ source = { { html : MAIN_SCRIPT ( videoId , playList , initialPlayerParams ) } }
175+ userAgent = {
176+ forceAndroidAutoplay
177+ ? Platform . select ( { android : CUSTOM_USER_AGENT , ios : '' } )
178+ : ''
179+ }
180+ onShouldStartLoadWithRequest = { request => {
181+ return request . mainDocumentURL === 'about:blank' ;
182+ } }
173183 { ...webViewProps }
174184 />
175185 </ View >
0 commit comments