Hello everyone, i've been searching for a couple of days and have not found a reliable way to play a youtube video the way I need to.
I have a video that I will be showing in my app, it's a tutorial video, I need the video to automatically start playing as soon as it loads and it needs to play with the sound on.
I have tried this using a WebView, and although it loads the video, it seems i need some js knowledge to be able to play the video and unmute it when it starts playing. I have been able to generate some js scripts using chatgpt and other sources on the web, but none seem to do what I need to.
I also tried using Erel's Simple Media Manager library, which as I understand works with ExoPlayer, and the way it works is by loading the video in a webview since it seems that the video can not be played or loaded natively with ExoPlayer.
With all this said, I need to find a solution, Here's what I have tried so far:
This code loads the video on a webview and it starts playing automatically, but after the 500 milliseconds timer, it unmutes the video but then the Video stops playing, I've read in another forum that you can not start a video unmuted as it is a restriction by YouTube, but I still think there's got to be a way to do it, i'm just not very good at js.
I'd like to read other people's opinions on this, Has anyone else encountered this, if so how did you figure it out?
Thanks,
Walter
I have a video that I will be showing in my app, it's a tutorial video, I need the video to automatically start playing as soon as it loads and it needs to play with the sound on.
I have tried this using a WebView, and although it loads the video, it seems i need some js knowledge to be able to play the video and unmute it when it starts playing. I have been able to generate some js scripts using chatgpt and other sources on the web, but none seem to do what I need to.
I also tried using Erel's Simple Media Manager library, which as I understand works with ExoPlayer, and the way it works is by loading the video in a webview since it seems that the video can not be played or loaded natively with ExoPlayer.
With all this said, I need to find a solution, Here's what I have tried so far:
WebView Player:
Dim html As String = $"<!DOCTYPE html>
<html>
<body>
<div id="player"></div>
<script>
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '100%',
width: '100%',
videoId: '${videoID}',
playerVars: {
'autoplay': 0,
'mute': 1, // Start muted to bypass autoplay restriction
'controls': 1,
'playsinline': 1
},
events: {
'onReady': onPlayerReady
}
});
}
function onPlayerReady(event) {
event.target.playVideo();
setTimeout(function() {
player.unMute(); // Unmute after 500 milliseconds
}, 500);
}
</script>
</body>
</html>
"$
This code loads the video on a webview and it starts playing automatically, but after the 500 milliseconds timer, it unmutes the video but then the Video stops playing, I've read in another forum that you can not start a video unmuted as it is a restriction by YouTube, but I still think there's got to be a way to do it, i'm just not very good at js.
I'd like to read other people's opinions on this, Has anyone else encountered this, if so how did you figure it out?
Thanks,
Walter