mirror of
https://github.com/KevinMidboe/zoff.git
synced 2025-10-29 18:00:23 +00:00
Fixed issue with duplicates and player
- Fixed issue where duplicates sometimes shows up in playlist - Fixed issue where player starts playing when server is restarted and the user has paused the song
This commit is contained in:
@@ -154,7 +154,7 @@ function skip(list, guid, coll, offline, socket) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function change_song(coll, error, id) {
|
function change_song(coll, error, id, callback) {
|
||||||
db.collection(coll).find({views:{$exists:true}}, function(err, docs){
|
db.collection(coll).find({views:{$exists:true}}, function(err, docs){
|
||||||
var startTime = docs[0].startTime;
|
var startTime = docs[0].startTime;
|
||||||
if(docs !== null && docs.length !== 0)
|
if(docs !== null && docs.length !== 0)
|
||||||
@@ -185,8 +185,10 @@ function change_song(coll, error, id) {
|
|||||||
db.collection(coll).remove({now_playing:true, id:id}, function(err, docs){
|
db.collection(coll).remove({now_playing:true, id:id}, function(err, docs){
|
||||||
var next_song;
|
var next_song;
|
||||||
if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id;
|
if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id;
|
||||||
List.change_song_post(coll, next_song);
|
List.change_song_post(coll, next_song, callback);
|
||||||
|
if(!callback) {
|
||||||
io.to(coll).emit("channel", {type: "deleted", value: now_playing_doc[0].id, removed: true});
|
io.to(coll).emit("channel", {type: "deleted", value: now_playing_doc[0].id, removed: true});
|
||||||
|
}
|
||||||
db.collection("frontpage_lists").update({_id: coll, count: {$gt: 0}}, {$inc: {count: -1}, $set:{accessed: Functions.get_time()}}, {upsert: true}, function(err, docs){});
|
db.collection("frontpage_lists").update({_id: coll, count: {$gt: 0}}, {$inc: {count: -1}, $set:{accessed: Functions.get_time()}}, {upsert: true}, function(err, docs){});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -201,7 +203,7 @@ function change_song(coll, error, id) {
|
|||||||
},{multi:true}, function(err, docs){
|
},{multi:true}, function(err, docs){
|
||||||
var next_song;
|
var next_song;
|
||||||
if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id;
|
if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id;
|
||||||
if(docs.n >= 1) List.change_song_post(coll, next_song);
|
if(docs.n >= 1) List.change_song_post(coll, next_song, callback);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -212,8 +214,10 @@ function change_song(coll, error, id) {
|
|||||||
db.collection(coll).remove({now_playing:true, id:id}, function(err, docs){
|
db.collection(coll).remove({now_playing:true, id:id}, function(err, docs){
|
||||||
var next_song;
|
var next_song;
|
||||||
if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id;
|
if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id;
|
||||||
List.change_song_post(coll, next_song);
|
List.change_song_post(coll, next_song, callback);
|
||||||
|
if(!callback) {
|
||||||
io.to(coll).emit("channel", {type: "deleted", value: now_playing_doc[0].id, removed: true});
|
io.to(coll).emit("channel", {type: "deleted", value: now_playing_doc[0].id, removed: true});
|
||||||
|
}
|
||||||
db.collection("frontpage_lists").update({_id: coll, count: {$gt: 0}}, {$inc: {count: -1}, $set:{accessed: Functions.get_time()}}, {upsert: true}, function(err, docs){});
|
db.collection("frontpage_lists").update({_id: coll, count: {$gt: 0}}, {$inc: {count: -1}, $set:{accessed: Functions.get_time()}}, {upsert: true}, function(err, docs){});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -227,7 +231,7 @@ function change_song(coll, error, id) {
|
|||||||
},{multi:true}, function(err, docs){
|
},{multi:true}, function(err, docs){
|
||||||
var next_song;
|
var next_song;
|
||||||
if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id;
|
if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id;
|
||||||
List.change_song_post(coll, next_song);
|
List.change_song_post(coll, next_song, callback);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -239,7 +243,7 @@ function change_song(coll, error, id) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function change_song_post(coll, next_song)
|
function change_song_post(coll, next_song, callback)
|
||||||
{
|
{
|
||||||
db.collection(coll).aggregate([{
|
db.collection(coll).aggregate([{
|
||||||
$match:{
|
$match:{
|
||||||
@@ -281,8 +285,12 @@ function change_song_post(coll, next_song)
|
|||||||
}
|
}
|
||||||
}, function(err, returnDocs){
|
}, function(err, returnDocs){
|
||||||
db.collection(coll).find({views:{$exists:true}}, function(err, conf){
|
db.collection(coll).find({views:{$exists:true}}, function(err, conf){
|
||||||
|
if(!callback) {
|
||||||
io.to(coll).emit("channel", {type: "song_change", time: Functions.get_time(), remove: conf[0].removeplay});
|
io.to(coll).emit("channel", {type: "song_change", time: Functions.get_time(), remove: conf[0].removeplay});
|
||||||
List.send_play(coll);
|
List.send_play(coll);
|
||||||
|
} else {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
Frontpage.update_frontpage(coll, docs[0].id, docs[0].title);
|
Frontpage.update_frontpage(coll, docs[0].id, docs[0].title);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -339,6 +347,11 @@ function send_list(coll, socket, send, list_send, configs, shuffled)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
if(Functions.get_time()-conf[0].startTime > np_docs[0].duration){
|
||||||
|
List.change_song(coll, false, np_docs[0].id, function() {
|
||||||
|
List.send_list(coll, socket, send, list_send, configs, shuffled);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
if(list_send) {
|
if(list_send) {
|
||||||
io.to(coll).emit("channel", {type: "list", playlist: docs, shuffled: shuffled});
|
io.to(coll).emit("channel", {type: "list", playlist: docs, shuffled: shuffled});
|
||||||
@@ -351,6 +364,7 @@ function send_list(coll, socket, send, list_send, configs, shuffled)
|
|||||||
List.send_play(coll, socket);
|
List.send_play(coll, socket);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
if(list_send) {
|
if(list_send) {
|
||||||
@@ -454,7 +468,6 @@ function send_play(coll, socket)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch(e){
|
} catch(e){
|
||||||
console.log(e);
|
|
||||||
if(socket) {
|
if(socket) {
|
||||||
socket.emit("np", {});
|
socket.emit("np", {});
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ var Player = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
console.log(paused);
|
||||||
|
console.log(Player.player.getPlayerState());
|
||||||
state = Player.player.getPlayerState();
|
state = Player.player.getPlayerState();
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
state = null;
|
state = null;
|
||||||
@@ -131,16 +133,16 @@ var Player = {
|
|||||||
}catch(e){}
|
}catch(e){}
|
||||||
|
|
||||||
Player.getTitle(song_title, viewers);
|
Player.getTitle(song_title, viewers);
|
||||||
//Player.setBGimage(video_id);
|
|
||||||
//if(player_ready && !Helper.mobilecheck())
|
|
||||||
if(player_ready && !window.MSStream) {
|
if(player_ready && !window.MSStream) {
|
||||||
try {
|
try {
|
||||||
var compared;
|
var compared;
|
||||||
try {
|
try {
|
||||||
compared = Player.player.getVideoUrl().split('v=')[1] != video_id;
|
compared = Player.player.getVideoUrl().split('v=')[1] != video_id && state != 2;
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
compared = true;
|
compared = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log("Compared", compared);
|
||||||
if(compared || chromecastAvailable){
|
if(compared || chromecastAvailable){
|
||||||
|
|
||||||
Player.loadVideoById(video_id, duration);
|
Player.loadVideoById(video_id, duration);
|
||||||
@@ -169,6 +171,7 @@ var Player = {
|
|||||||
setTimeout(function(){Player.loaded = true;},500);
|
setTimeout(function(){Player.loaded = true;},500);
|
||||||
}
|
}
|
||||||
}catch(e) {
|
}catch(e) {
|
||||||
|
console.log(e);
|
||||||
if(chromecastAvailable) {
|
if(chromecastAvailable) {
|
||||||
Player.loadVideoById(video_id, duration);
|
Player.loadVideoById(video_id, duration);
|
||||||
Player.seekTo(seekTo);
|
Player.seekTo(seekTo);
|
||||||
|
|||||||
Reference in New Issue
Block a user