Files
UniversalMusicPlayer/add-on/youtube.js
Markil3 ede9132279 Adds the ability to play youtube videos.
It still needs a bit of work, but playing and pausing are operational.
2021-08-16 22:42:44 -06:00

76 lines
961 B
JavaScript

console.debug("Loading youtube.js")
var video;
function onload()
{
video = document.getElementsByClassName('video-stream html5-main-video')[0]
}
function getState()
{
if (!video)
{
return 4;
}
else if (video.ended)
{
return 3;
}
else if (video.paused)
{
return 1;
}
else
{
return 0;
}
}
function getTime()
{
return video.currentTime;
}
function getLength()
{
return video.duration;
}
function play()
{
if (video != null)
{
video.play();
return true;
}
return false;
}
function pause()
{
if (video != null)
{
video.pause();
return true;
}
return false;
}
function seek(time)
{
if (video != null)
{
video.currentTime = time;
return true;
}
return false;
}
if (document.readyState === "complete")
{
onload();
}
else
{
window.addEventListener("load", onload);
}