Advertisement
The_red_Freak

Untitled

Jun 22nd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 3.36 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="de">
  3.     <head>
  4.         <meta charset="UTF-8">
  5.         <title>Youtube Remote</title>
  6.         <script src="https://www.youtube.com/iframe_api"></script>
  7.         <script src="https://code.jquery.com/jquery-3.2.1.js"></script>
  8.     </head>
  9.           <body style="margin: 0; display: flex;">
  10.                 <div id="player" ></div>
  11.                 <script type="text/javascript">
  12.                     var player;
  13.                     var cue = ['Xm8UTv6LSf0','Q2IaKsHFjr8','NFB6Y2Qt8ag'];
  14.                     var previousIndex = 0;
  15.                     function onYouTubeIframeAPIReady() {
  16.                         player = new YT.Player('player',{
  17.                             height: $(window).height(),
  18.                             width: $(window).width(),
  19.                             playerVars: {
  20.                                 playlist: cue.join(','),
  21.                                 listType: 'playlist',
  22.                                 color: "white",
  23.                                 controls: 2,
  24.                                 enablejsapi: 1,
  25.                                 fs: 0,
  26.                             },
  27.                             events: {
  28.                                 onStateChange: function (event) {
  29.                                    if (event.data == -1 || event.data == 0) {
  30.                                        console.log("\n\n\n\n\n\n\n\n\n\n\n\n\n\nPlayer finished");        <-- Debug
  31.                                       var index = player.getPlaylistIndex();
  32.                                       if (player.getPlaylist().length != cue.length) {
  33.                                           player.loadPlaylist(cue, previousIndex + 1);
  34.                                       }
  35.                                       previousIndex = index;
  36.                                   }
  37.                               }
  38.                           }
  39.                        });
  40.                    }
  41.  
  42.                    var s = new WebSocket("ws://" + window.location.host + ":80/socket");
  43.  
  44.                    s.onopen = function (data) {s.send("[SERVER]")};
  45.                    s.onclose = function (data) {  };
  46.                    s.onmessage = function (data) {
  47.                        var msg = data.data;
  48.                        if(msg.substr(0,"[QUEUE]".length) == "[QUEUE]"){
  49.                            msg = msg.substr("[QUEUE]".length);
  50.                            console.log(msg);
  51.                            if(msg.indexOf(",") > -1) {
  52.                                 for (var x in msg.split(",")) {
  53.                                     cue.push(x);
  54.                                 }
  55.                             } else {
  56.                                 cue.push(msg);
  57.                             }
  58.  
  59.                         } else if(msg.substr(0,"[PLAY]".length) == "[PLAY]"){
  60.                             player.playVideo();
  61.                         } else if(msg.substr(0,"[PAUSE]".length) == "[PAUSE]"){
  62.                             player.pauseVideo();
  63.                         } else if(msg.substr(0,"[NEXT]".length) == "[NEXT]"){
  64.                             player.nextVideo();
  65.                         } else if(msg.substr(0,"[PREV]".length) == "[PREV]"){
  66.                             player.previousVideo();
  67.                         }
  68.                     };
  69.                 </script>
  70.      </body>
  71. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement