Hi can anyone help with this problem. The youtube -plugin can’t do this. I assume this would be meaningful for many developers. So there is code that works well when writing/controlling youtube iframe:
Just as a suggestion, you should check out the plyr package. I am currently using it to play audio files and will soon be implementing YouTube and Vimeo videos. Audio has worked great so far.
It has a currentTime property along with a timeupdate event.
That sounds very good option. Setting up the Plyr player was not very easy. I use Ionic3/type script in the current project. I need to look after solution to make it work.
private player;
{}
private callInitPlayer(videoId){
let tag = document.createElement('script');
tag.src = 'https://www.youtube.com/iframe_api';
// console.log('tag: ', tag);
let firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// console.log('firstScript:', firstScriptTag);
this.player = new YT.Player('player', {
// height: '390’,
width: '100%',
videoId: id,
playerVars: {'playsinline': 1},
events: {'onReady': this.onPlayerReady,
'onStateChange': this.onPlayerStateChange}
});
}
// 4. The API will call this function when the video player is ready.
private onPlayerReady(event) {
event.target.playVideo();
}
// 5. The API calls this function when the player’s state changes.
// The function indicates that when playing a video (state=1),
// the player should play for six seconds and then stop.
private onPlayerStateChange(event) {
console.log('onPlayerStateChange_event: ', event);
}
So with these functions you can in set the youtube to page: