mirror of
https://github.com/BluemediaDev/muse.git
synced 2025-04-19 21:03:56 +02:00
Fix position tracking bug and catch ffmpeg errors
This commit is contained in:
parent
e1c9f988c3
commit
dc70a37e96
2 changed files with 35 additions and 15 deletions
|
@ -16,7 +16,8 @@ export default class implements Command {
|
||||||
public name = 'queue';
|
public name = 'queue';
|
||||||
public aliases = ['q'];
|
public aliases = ['q'];
|
||||||
public examples = [
|
public examples = [
|
||||||
['queue', 'shows current queue']
|
['queue', 'shows current queue'],
|
||||||
|
['queue 2', 'shows second page of queue']
|
||||||
];
|
];
|
||||||
|
|
||||||
private readonly playerManager: PlayerManager;
|
private readonly playerManager: PlayerManager;
|
||||||
|
|
|
@ -180,6 +180,8 @@ export default class {
|
||||||
manualForward(): void {
|
manualForward(): void {
|
||||||
if (this.queuePosition < this.queue.length) {
|
if (this.queuePosition < this.queue.length) {
|
||||||
this.queuePosition++;
|
this.queuePosition++;
|
||||||
|
this.positionInSeconds = 0;
|
||||||
|
this.stopTrackingPosition();
|
||||||
} else {
|
} else {
|
||||||
throw new Error('No songs in queue to forward to.');
|
throw new Error('No songs in queue to forward to.');
|
||||||
}
|
}
|
||||||
|
@ -189,6 +191,7 @@ export default class {
|
||||||
if (this.queuePosition - 1 >= 0) {
|
if (this.queuePosition - 1 >= 0) {
|
||||||
this.queuePosition--;
|
this.queuePosition--;
|
||||||
this.positionInSeconds = 0;
|
this.positionInSeconds = 0;
|
||||||
|
this.stopTrackingPosition();
|
||||||
|
|
||||||
if (this.status !== STATUS.PAUSED) {
|
if (this.status !== STATUS.PAUSED) {
|
||||||
await this.play();
|
await this.play();
|
||||||
|
@ -286,7 +289,7 @@ export default class {
|
||||||
const cachedPath = this.getCachedPath(url);
|
const cachedPath = this.getCachedPath(url);
|
||||||
|
|
||||||
let ffmpegInput = '';
|
let ffmpegInput = '';
|
||||||
const ffmpegInputOptions = [];
|
const ffmpegInputOptions: string[] = [];
|
||||||
let shouldCacheVideo = false;
|
let shouldCacheVideo = false;
|
||||||
|
|
||||||
if (await this.isCached(url)) {
|
if (await this.isCached(url)) {
|
||||||
|
@ -345,7 +348,17 @@ export default class {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create stream and pipe to capacitor
|
// Create stream and pipe to capacitor
|
||||||
const youtubeStream = ffmpeg(ffmpegInput).inputOptions(ffmpegInputOptions).noVideo().audioCodec('libopus').outputFormat('webm').pipe() as PassThrough;
|
return new Promise((resolve, reject) => {
|
||||||
|
const youtubeStream = ffmpeg(ffmpegInput)
|
||||||
|
.inputOptions(ffmpegInputOptions)
|
||||||
|
.noVideo()
|
||||||
|
.audioCodec('libopus')
|
||||||
|
.outputFormat('webm')
|
||||||
|
.on('error', error => {
|
||||||
|
console.error(error);
|
||||||
|
reject(error);
|
||||||
|
})
|
||||||
|
.pipe() as PassThrough;
|
||||||
|
|
||||||
const capacitor = new WriteStream();
|
const capacitor = new WriteStream();
|
||||||
|
|
||||||
|
@ -357,13 +370,19 @@ export default class {
|
||||||
const cacheStream = createWriteStream(cacheTempPath);
|
const cacheStream = createWriteStream(cacheTempPath);
|
||||||
|
|
||||||
cacheStream.on('finish', async () => {
|
cacheStream.on('finish', async () => {
|
||||||
|
// Only move if size is non-zero (may have errored out)
|
||||||
|
const stats = await fs.stat(cacheTempPath);
|
||||||
|
|
||||||
|
if (stats.size !== 0) {
|
||||||
await fs.rename(cacheTempPath, cachedPath);
|
await fs.rename(cacheTempPath, cachedPath);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
capacitor.createReadStream().pipe(cacheStream);
|
capacitor.createReadStream().pipe(cacheStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
return capacitor.createReadStream();
|
resolve(capacitor.createReadStream());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private startTrackingPosition(initalPosition?: number): void {
|
private startTrackingPosition(initalPosition?: number): void {
|
||||||
|
|
Loading…
Add table
Reference in a new issue