Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3645

How to stop autoplay if autoplay switch is false in Youtube iFrame API

$
0
0

I tried various solutions like setting autoplay to 0Adding logic to YT.PlayerState.ENDED:Changing logic for onPlayerReady()

But still nothing works. It still autoplays. Can anyone help me.

var youtubePlaylistID = "%1$s";        var youtubeVideoID = "%1$s";        var initialVideoIndex = %3$d;        var mIsAutoPlay = true;        var player;        function onYouTubePlayerAPIReady() {            player = new YT.Player('iframe_player_api', {                width: videoWidth,                height: videoHeight,                videoId: youtubeVideoID,                playerVars: {'modestbranding': 1,'showinfo': 0,'rel': 0,'fs': 0,'autoplay': 1,'controls': 0,'listType': 'playlist','list': youtubePlaylistID,'index': initialVideoIndex                },                events: {'onReady': onPlayerReady,'onStateChange': onPlayerStateChange                }            });        }        function onPlayerReady(event) {            event.target.playVideo();        }        function onPlayerStateChange(event) {            switch (event.data) {                case YT.PlayerState.ENDED:                    if(mIsAutoPlay == true) {                        event.target.loadVideoById();                    } else {                        event.target.cueVideoById();                    }                    break;                case YT.PlayerState.PLAYING:                    break;                case YT.PlayerState.PAUSED:                    break;                case YT.PlayerState.BUFFERING:                    break;                case YT.PlayerState.CUED:                    break;            }

I expect it to be autoplaying if mIsAutoPlay is true if false it will just stop.


Viewing all articles
Browse latest Browse all 3645

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>