Fix weird audio playback bug between subsequent streams on an AudioPlayer

This commit is contained in:
Amish Shah
2016-12-28 23:21:34 +00:00
parent 00254f35b0
commit e7824d6515
2 changed files with 11 additions and 4 deletions

View File

@@ -217,7 +217,6 @@ class StreamDispatcher extends EventEmitter {
data.count++;
data.sequence = (data.sequence + 1) < 65536 ? data.sequence + 1 : 0;
data.timestamp = data.timestamp + 4294967295 ? data.timestamp + 960 : 0;
this.sendBuffer(buffer, data.sequence, data.timestamp);
const nextTime = data.length + (data.startTime + data.pausedTime + (data.count * data.length) - Date.now());
@@ -247,7 +246,11 @@ class StreamDispatcher extends EventEmitter {
data.length = 20;
data.missed = 0;
this.stream.once('readable', () => this.process());
this.stream.once('readable', () => {
data.startTime = null;
data.count = 0;
this.process();
});
}
setPaused(paused) { this.setSpeaking(!(this.paused = paused)); }

View File

@@ -169,7 +169,9 @@ client.on('message', msg => {
if (msg.content.startsWith('/play')) {
console.log('I am now going to play', msg.content);
const chan = msg.content.split(' ').slice(1).join(' ');
con.playStream(ytdl(chan, {filter : 'audioonly'}), { passes : 4 });
const s = ytdl(chan, {filter:'audioonly'}, { passes : 3 });
s.on('error', e => console.log(`e w stream 1 ${e}`));
con.playStream(s);
}
if (msg.content.startsWith('/join')) {
const chan = msg.content.split(' ').slice(1).join(' ');
@@ -177,7 +179,9 @@ client.on('message', msg => {
.then(conn => {
con = conn;
msg.reply('done');
disp = conn.playStream(ytdl(song, {filter:'audioonly'}), { passes : 3 });
const s = ytdl(song, {filter:'audioonly'}, { passes : 3 });
s.on('error', e => console.log(`e w stream 2 ${e}`));
disp = conn.playStream(s);
conn.player.on('debug', console.log);
conn.player.on('error', err => console.log(123, err));
})