Note: It also works fine in the incognito window of Chrome browser and other browsers (like Mozilla) on Mobile.
It loads the video data successfully but when I try to play the video it shows me an error.
Run this code using local environment like vs-code etc.
This snippet works on a computer browser properly, but when I open the same page using IP on my mobile Chrome browser, I got an error, but it works in the incognito mode and other browsers too.
I don't know why it is behaving like this, It would be really helpful if anyone can rid of this.
Computer Chrome Browser[Working fine]
Mobile Chrome Browser [Not Playing the video]
//YouTube embed with YouTube Iframe API
var tag = document.createElement("script");
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName("script")[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// YouTube embed player details
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player("player", {
height: "390",
width: "640",
videoId: "668nUCeBHyY",
//Features
playerVars: {
controls: 0,
rel: 0,
disablekb: 1,
},
});
}
//functions
function playYT() {
player.playVideo();
}
function pauseYT() {
player.pauseVideo();
}
<div style="pointer-events:none" id="player"></div><br><br>
<button onclick="playYT()">Play</button>
<button onclick="pauseYT()">Pause</button>