Skip to content

Commit f741b21

Browse files
committed
minor fix to enable android autoplay
add documentation entry for the fix
1 parent a8a4a7e commit f741b21

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

doc/readme.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,17 @@ the video from the youtube player UI
127127

128128
> **note on autoPlay**: The HTML5 `<video>` element, in certain mobile browsers (such as Chrome and Safari), only allows playback to take place if it's initiated by a user interaction (such as tapping on the player).
129129
130+
A work around to get the video to autoplay is to add these parameters to alter the user agent of the webview.
131+
Add the following code to the component to make autoplay for on android. (ios seems to work out of the box)
132+
133+
```JSX
134+
webViewProps={{
135+
userAgent:
136+
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36',
137+
mediaPlaybackRequiresUserAction: false,
138+
}}
139+
```
140+
130141
## onChangeState
131142

132143
**_function(event: string)_**

src/YoutubeIframe.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ const YoutubeIframe = (
167167
ref={webViewRef}
168168
originWhitelist={['*']}
169169
source={{html: MAIN_SCRIPT(videoId, playList, initialPlayerParams)}}
170+
mediaPlaybackRequiresUserAction={false}
170171
allowsInlineMediaPlayback
171172
onMessage={onWebMessage}
172173
{...webViewProps}

0 commit comments

Comments
 (0)