@@ -15,12 +15,15 @@ const DEFAULT_PLAYER_VARS = {
1515 showinfo : 0
1616}
1717
18+ let count = 0
19+
1820export default class YouTube extends Base {
1921 static propTypes = propTypes
2022 static defaultProps = defaultProps
2123 static canPlay ( url ) {
2224 return MATCH_URL . test ( url )
2325 }
26+ playerId = PLAYER_ID + '-' + count ++
2427 componentDidMount ( ) {
2528 if ( ! this . props . url && this . props . youtubeConfig . preload ) {
2629 this . preloading = true
@@ -33,7 +36,9 @@ export default class YouTube extends Base {
3336 return Promise . resolve ( window [ SDK_GLOBAL ] )
3437 }
3538 return new Promise ( ( resolve , reject ) => {
39+ const previousOnReady = window . onYouTubeIframeAPIReady
3640 window . onYouTubeIframeAPIReady = function ( ) {
41+ if ( previousOnReady ) previousOnReady ( )
3742 resolve ( window [ SDK_GLOBAL ] )
3843 }
3944 loadScript ( SDK_URL , err => {
@@ -53,7 +58,7 @@ export default class YouTube extends Base {
5358 return
5459 }
5560 this . getSDK ( ) . then ( YT => {
56- this . player = new YT . Player ( PLAYER_ID , {
61+ this . player = new YT . Player ( this . playerId , {
5762 width : '100%' ,
5863 height : '100%' ,
5964 videoId : id ,
@@ -103,6 +108,6 @@ export default class YouTube extends Base {
103108 }
104109 render ( ) {
105110 const style = { display : this . props . url ? 'block' : 'none' }
106- return < div id = { PLAYER_ID } style = { style } />
111+ return < div id = { this . playerId } style = { style } />
107112 }
108113}
0 commit comments