Skip to content

Commit 5760b85

Browse files
authored
Add ffmpegPath option (#1933)
* Add ffmpegPath option * Reorder ffmpegPath option to the top * Test for ffmpeg * Add: ffmpeg tests * Remove useless imports
1 parent 5a5da80 commit 5760b85

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

packages/discord-player/__test__/Player.spec.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { afterEach, describe, expect, it } from 'vitest';
1+
import { afterEach, describe, expect, it, test } from 'vitest';
22
import { Player, SearchResult } from '../src/index';
33
import { Client, IntentsBitField } from 'discord.js';
44

@@ -38,4 +38,14 @@ describe('Player', () => {
3838

3939
expect(response).toBeInstanceOf(SearchResult);
4040
});
41+
42+
test("should set process.env.FFMPEG_PATH to given path", () => {
43+
// not actual ffmpeg path. just dummy
44+
new Player(client, {
45+
ffmpegPath: "./packages/ffmpeg",
46+
ignoreInstance: true
47+
})
48+
49+
expect(process.env.FFMPEG_PATH).toBe("./packages/ffmpeg")
50+
})
4151
});

packages/discord-player/src/Player.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ export class Player extends PlayerEventsEmitter<PlayerEvents> {
104104

105105
super([PlayerEvent.Error]);
106106

107+
if(options.ffmpegPath) {
108+
if(typeof options.ffmpegPath !== "string") throw new TypeError(`Expected type "string" for options.ffmpegPath. Got ${typeof options.ffmpegPath} instead`)
109+
110+
process.env.FFMPEG_PATH = options.ffmpegPath
111+
}
112+
107113
/**
108114
* The discord.js client
109115
* @type {Client}

packages/discord-player/src/types/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,4 +531,8 @@ export interface PlayerInitOptions {
531531
* The probe timeout in milliseconds. Defaults to 5000.
532532
*/
533533
probeTimeout?: number;
534+
/**
535+
* Configure ffmpeg path
536+
*/
537+
ffmpegPath?: string;
534538
}

0 commit comments

Comments
 (0)