Skip to content

Commit

Permalink
Fix Playing [0] undefined Bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Yonle authored May 18, 2021
1 parent 1d62c5c commit 75cc8a3
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 18 deletions.
20 changes: 14 additions & 6 deletions cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,31 @@ async function play(n) {
}
let filename = song[new Number(n) - 1] || song[songnum++];
if (n) songnum = n;
if (!filename) {
filename = song[0];
songnum = 1;
}

if (loop) {
if (!n) {
songnum = songnum - 1;
filename = song[songnum - 1];
if (songnum != 1) {
songnum = songnum - 1;
filename = song[songnum - 1];
} else {
songnum = manager.readSongs().length;
filename = song[songnum - 1];
}
}
}

if (random) {
if (!n) {
songnum = Math.floor(Math.random() * song.length);
filename = song[songnum - 1];
}
}

if (!filename || !songnum) {
filename = song[0];
songnum = 1;
}

stream = fs.createReadStream(`${dirname}/${filename}`).pipe(convert()).pipe(Throttle(24000));
stream.on("data", (chunk) => {
sink.forEach((s) => {
Expand Down
19 changes: 13 additions & 6 deletions cli/tcp.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,16 @@ async function play(n) {
}
let filename = song[new Number(n) - 1] || song[songnum++];
if (n) songnum = n;
if (!filename) {
filename = song[0];
songnum = 1;
}

if (loop) {
if (!n) {
songnum = songnum - 1;
filename = song[songnum - 1];
if (songnum != 1) {
songnum = songnum - 1;
filename = song[songnum - 1];
} else {
songnum = manager.readSongs().length;
filename = song[songnum - 1];
}
}
}
if (random) {
Expand All @@ -106,6 +107,12 @@ async function play(n) {
filename = song[songnum - 1];
}
}

if (!filename || !songnum) {
filename = song[0];
songnum = 1;
}

stream = fs.createReadStream(`${dirname}/${filename}`).pipe(convert()).pipe(Throttle(24000));
stream.on("data", (chunk) => {
sink.forEach((s) => {
Expand Down
19 changes: 13 additions & 6 deletions cli/udp.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,16 @@ async function play(n) {
}
let filename = song[new Number(n) - 1] || song[songnum++];
if (n) songnum = n;
if (!filename) {
filename = song[0];
songnum = 1;
}

if (loop) {
if (!n) {
songnum = songnum - 1;
filename = song[songnum - 1];
if (songnum != 1) {
songnum = songnum - 1;
filename = song[songnum - 1];
} else {
songnum = manager.readSongs().length;
filename = song[songnum - 1];
}
}
}
if (random) {
Expand All @@ -100,6 +101,12 @@ async function play(n) {
filename = song[songnum - 1];
}
}

if (!filename || !songnum) {
filename = song[0];
songnum = 1;
}

stream = fs.createReadStream(`${dirname}/${filename}`).pipe(convert()).pipe(Throttle(24000));
stream.on("data", (chunk) => {
sink.forEach((s, id) => {
Expand Down

0 comments on commit 75cc8a3

Please sign in to comment.