Skip to content

Commit f5227d9

Browse files
committed
fix android autoplay issues (#2 #3)
1 parent d13844b commit f5227d9

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/YoutubeIframe.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import React, {
55
useImperativeHandle,
66
forwardRef,
77
useState,
8+
Platform,
89
} from 'react';
910
import {View, StyleSheet} from 'react-native';
1011
import WebView from 'react-native-webview';
@@ -18,19 +19,20 @@ const YoutubeIframe = (
1819
width,
1920
videoId,
2021
playList,
21-
playListStartIndex = 0,
2222
play = false,
23-
onChangeState = _event => {},
24-
onReady = _event => {},
25-
onError = _err => {},
26-
onPlaybackQualityChange = _quality => {},
2723
mute = false,
2824
volume = 100,
29-
playbackRate = 1,
30-
onPlaybackRateChange = _playbackRate => {},
31-
initialPlayerParams = {},
3225
webViewStyle,
3326
webViewProps,
27+
playbackRate = 1,
28+
onError = _err => {},
29+
onReady = _event => {},
30+
playListStartIndex = 0,
31+
initialPlayerParams = {},
32+
forceAndroidAutoplay = false,
33+
onChangeState = _event => {},
34+
onPlaybackQualityChange = _quality => {},
35+
onPlaybackRateChange = _playbackRate => {},
3436
},
3537
ref,
3638
) => {
@@ -170,6 +172,10 @@ const YoutubeIframe = (
170172
mediaPlaybackRequiresUserAction={false}
171173
allowsInlineMediaPlayback
172174
onMessage={onWebMessage}
175+
userAgent={Platform.select({
176+
android:
177+
'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',
178+
})}
173179
{...webViewProps}
174180
/>
175181
</View>

0 commit comments

Comments
 (0)