add rudimentary playlist
Signed-off-by: Christian Richter <crichter@owncloud.com>
This commit is contained in:
@@ -35,7 +35,7 @@
|
|||||||
<div class="title">
|
<div class="title">
|
||||||
<h1>Weirdradio</h1>
|
<h1>Weirdradio</h1>
|
||||||
</div>
|
</div>
|
||||||
<div class="playlist">
|
<div id="playlist" class="playlist">
|
||||||
{playlist}
|
{playlist}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -47,7 +47,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
<script>
|
<script>
|
||||||
// 2. This code loads the IFrame Player API code asynchronously.
|
var playlist = []
|
||||||
var tag = document.createElement('script');
|
var tag = document.createElement('script');
|
||||||
|
|
||||||
tag.src = "https://www.youtube.com/iframe_api";
|
tag.src = "https://www.youtube.com/iframe_api";
|
||||||
@@ -72,14 +72,10 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. The API will call this function when the video player is ready.
|
|
||||||
function onPlayerReady(event) {
|
function onPlayerReady(event) {
|
||||||
event.target.playVideo();
|
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.
|
|
||||||
var done = false;
|
var done = false;
|
||||||
function onPlayerStateChange(event) {
|
function onPlayerStateChange(event) {
|
||||||
if (event.data == 0) {
|
if (event.data == 0) {
|
||||||
@@ -93,9 +89,6 @@
|
|||||||
function stopVideo() {
|
function stopVideo() {
|
||||||
player.stopVideo();
|
player.stopVideo();
|
||||||
}
|
}
|
||||||
</script>
|
|
||||||
|
|
||||||
<script lang="Javascript">
|
|
||||||
|
|
||||||
function connectSocket() {
|
function connectSocket() {
|
||||||
baseUrl = (window.location.host).replace("8080", "8090")
|
baseUrl = (window.location.host).replace("8080", "8090")
|
||||||
@@ -106,6 +99,8 @@
|
|||||||
socket.onmessage = function(event) {
|
socket.onmessage = function(event) {
|
||||||
data = JSON.parse(event.data)
|
data = JSON.parse(event.data)
|
||||||
if (data["videoId"] != undefined && data["videoId"] != null) {
|
if (data["videoId"] != undefined && data["videoId"] != null) {
|
||||||
|
playlist.push(data)
|
||||||
|
updatePlaylist()
|
||||||
player.loadVideoById(data["videoId"])
|
player.loadVideoById(data["videoId"])
|
||||||
player.playVideo()
|
player.playVideo()
|
||||||
console.log(`[message] Data received from server: ${event.data}`);
|
console.log(`[message] Data received from server: ${event.data}`);
|
||||||
@@ -114,5 +109,14 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updatePlaylist() {
|
||||||
|
pl = document.getElementById("playlist")
|
||||||
|
output = ""
|
||||||
|
playlist.forEach((e) => {
|
||||||
|
output = output + `<div><div>${e.title}</div><div>${e.link}</div></div>`
|
||||||
|
})
|
||||||
|
pl.innerHTML = output
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
</html>
|
</html>
|
||||||
Reference in New Issue
Block a user