Skip to content

Commit

Permalink
fix bug when playnext
Browse files Browse the repository at this point in the history
  • Loading branch information
lucbu committed Apr 19, 2017
1 parent d994d35 commit 30e70b7
Showing 1 changed file with 38 additions and 37 deletions.
75 changes: 38 additions & 37 deletions playlist/Playlist.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,57 @@
var os = require('os');

function Playlist(player) {
// console.log('Create Playlist');
// console.log('Create Playlist');
this.player = player;
this.queue = [];
this.playing = undefined;
}

Playlist.prototype.addToQueue = function (playlist_item, cb) {
this.queue.push(playlist_item);
if(this.queue.length == 1){
this.playNext();
} else {
playlist_item.sound.downloadFile();
}
this.queue.push(playlist_item);
if(this.queue.length == 1){
this.playNext();
} else {
playlist_item.sound.downloadFile();
}
}

Playlist.prototype.playNext = function(force){
if('undefined' === typeof force){
force=false;
}
if(force){
this.queue.shift();
var isWin = /^win/.test(os.platform());
if(!isWin) {
this.player.audio.kill('SIGKILL');
} else {
var cp = require('child_process');
cp.exec('taskkill /PID ' + this.player.audio.pid + ' /T /F', function (error, stdout, stderr) {});
if('undefined' === typeof force){
force=false;
}
this.player.status = 'offair'
}
var playlist = this;
var next = this.queue[0];
this.playing = undefined;
if('undefined' !== typeof next){
if(next.like >= next.dislike){
this.playing = next;
this.player.playSound(next.sound, function(){
playlist.queue.shift();
next.sound.deleteFile();
if('undefined' !== next.endPlaying){
next.endPlaying()
if(force){
this.queue.shift();
var isWin = /^win/.test(os.platform());
if(!isWin) {
this.player.audio.kill('SIGKILL');
} else {
var cp = require('child_process');
cp.exec('taskkill /PID ' + this.player.audio.pid + ' /T /F', function (error, stdout, stderr) {});
}
playlist.playNext();
});
this.player.status = 'offair'
} else {
this.queue.shift();
next.sound.deleteFile();
this.playNext();
var playlist = this;
var next = this.queue[0];
this.playing = undefined;
if('undefined' !== typeof next){
if(next.like >= next.dislike){
this.playing = next;
this.player.playSound(next.sound, function(){
playlist.queue.shift();
next.sound.deleteFile();
if('undefined' !== next.endPlaying){
next.endPlaying()
}
playlist.playNext();
});
} else {
this.queue.shift();
next.sound.deleteFile();
this.playNext();
}
}
}
}
}

module.exports = Playlist;

0 comments on commit 30e70b7

Please sign in to comment.