Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
- <title>PJ_musicStream</title>
- <link rel="stylesheet" href="lib/tocas.min.css">
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
- <script src="lib/config.js"></script>
- <script>
- var now_song_id;
- $(document).ready(function(){
- function s_list_item_click(){
- console.log('inner s-list-item clicked event => $(this)');
- console.log($(this))
- console.log('inner s-list-item clicked event => $(this).val()');
- console.log($(this).val())
- console.log('inner s-list-item clicked event => $(this)[0].innerText');
- console.log($(this)[0].innerText) //this is ok
- console.log('inner s-list-item clicked event => Number($(this)[0].innerText.split(\' \')[0])');
- console.log(Number($(this)[0].innerText.split(' ')[0]))
- $.ajax({
- type: 'POST',
- url: domain+'/addQueue',
- dataType: 'json',
- data: {
- s_id: Number($(this)[0].innerText.split(' ')[0]),
- start_time: 0 //There's no way to set yet
- },
- success: function(res){
- //doesn't matter
- },
- error: function(xhr){
- console.log(xhr);
- }
- });
- updateQueueList();
- }
- function updateQueueList(){
- $('#queue-list').empty();
- $.ajax({
- type: 'POST',
- url: domain+'/getQueue',
- dataType: 'json',
- success: function(res){
- res.forEach(function(value, index){
- $('#queue-list').append(' \
- <div class="item queue-item"> \
- '+index+' ('+value.s_id+' '+value.s_name+' '+value.s_t+'sec) \
- </div> \
- <button class="ts icon button mini compact negative queue-item-remove"> \
- <i class="icon remove"></i> \
- </button> \
- <br /> \
- ');
- });
- $('.queue-item').click(queue_forcePlay);
- $('.queue-item-remove').click(removeQueue);
- },
- error: function(xhr){
- console.log(xhr);
- }
- });
- }
- function queue_forcePlay(){
- $.ajax({
- type: 'POST',
- url: domain+'/forcePlay',
- dataType: 'json',
- data: {
- queue_index: Number($(this)[0].innerText.split(' ')[0])
- },
- success: function(res){
- // doesn't matter
- },
- error: function(xhr){
- console.log(xhr);
- }
- });
- window.location.reload();
- }
- function removeQueue(){
- $.ajax({
- type: 'POST',
- url: domain+'/removeQueue',
- dataType: 'json',
- data: {
- queue_index: Number($(this).prev()[0].innerText.split(' ')[0])
- },
- success: function(res){
- // doesn't matter
- },
- error: function(xhr){
- console.log(xhr);
- }
- });
- updateQueueList();
- }
- $.ajax({
- type: 'POST',
- url: domain+'/getList',
- dataType: 'json',
- success: function(res){
- var type_object = {};
- $.each(res, function(index, value){
- if(!type_object[value.s_type]){
- type_object[value.s_type] = {};
- }
- // s_id as key
- type_object[value.s_type][value.s_id] = value;
- });
- $.each(type_object, function(index, value){
- $('#s-list').append(' \
- <div class="ts massive header">'+index+'</div> \
- ');
- $.each(value, function(index, value){
- $('#s-list').append(' \
- <div class="item s-list-item"> \
- <div class="header">'+value.s_id+' '+value.s_name+'</div> \
- '+value.s_t+'sec \
- </div> \
- ');
- });
- });
- $('.s-list-item').click(s_list_item_click);
- },
- error: function(xhr){
- console.log(xhr);
- }
- });
- $.ajax({
- type: 'POST',
- url: domain+'/getCurrent',
- dataType: 'json',
- success: function(res){
- console.log('/getCurrent => res');
- console.dir(res);
- if(!res['s_id'] && res['s_id'] !== 0){
- console.log('songs are not ready yet');
- return;
- }else{
- $('#player').attr('src', res.s_url);
- $('#player')[0].currentTime = res.now_Len;
- $('#player')[0].play();
- $('#player')[0].volume = volume;
- now_song_id=res.s_id
- $('#s-id').text(res.s_id);
- $('#s-title').text(res.s_name);
- $('#s-artist').text(res.s_description.artist);
- $('#s-album').text(res.s_description.album);
- $('#s-length').text(res.s_t);
- }
- },
- error: function(xhr){
- console.log(xhr);
- }
- });
- updateQueueList();
- setInterval(function(){
- $.ajax({
- type: 'POST',
- url: domain+'/getCurrent',
- dataType: 'json',
- success: function(res){
- console.log('Interval: check now len every 5sec => now_Len: '+res['now_Len'])
- if(!res['s_id'] && res['s_id'] !== 0){
- console.log('songs are not ready yet');
- return;
- }else{
- if(res['s_id'] !== now_song_id){
- window.location.reload();
- }
- var player_t = $('#player')[0].currentTime;
- if(Math.abs(player_t - res.now_Len) > 5){
- $('#player')[0].currentTime = res.now_Len;
- }
- }
- },
- error: function(xhr){
- console.log(xhr);
- }
- });
- },5000);
- $('#player').click(function(){
- window.location.reload();
- });
- })
- </script>
- </head>
- <body>
- <br>
- <div class="ts container stackable grid">
- <div class="sixteen wide column">
- <div class="ts center aligned raised segment">
- <video controls preload="none" id="player"></video>
- </div>
- </div>
- <div class="twelve wide column">
- <div class="ts raised segment">
- Id:<div id="s-id"></div>
- Title:<div id="s-title"></div>
- Artist:<div id="s-artist"></div>
- Album:<div id="s-album"></div>
- Length:<div id="s-length"></div>
- <!-- <br /> will be append in the end-->
- <div style="text-align: center;" id="queue-list">
- <div class="ts list selection divided" id="queue-list">
- <div class="item queue-item">
- -- QueueId(Very Important)(same as Array's index) --SPACE-- ( -- SongId --SPACE-- Title --SPACE-- Length -- ) --
- </div>
- <button class="ts icon button mini compact negative queue-item-remove">
- <i class="icon remove"></i>
- </button>
- </div>
- </div>
- </div>
- </div>
- <div class="four wide column" id="s-list">
- <div class="ts raised segment">
- <!-- <BIG classification header> -->
- <div class="ts list selection divided">
- <div class="item" id="s-list-item">
- <div class="header">-- Id --SPACE-- Title --</div>
- -- Length --
- </div>
- </div>
- </div>
- </div>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment