Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.kill is not a function #1311

Open
JulianAa14 opened this issue Nov 30, 2024 · 0 comments
Open

.kill is not a function #1311

JulianAa14 opened this issue Nov 30, 2024 · 0 comments

Comments

@JulianAa14
Copy link

JulianAa14 commented Nov 30, 2024

Version information

  • fluent-ffmpeg version: 2.1.3
  • ffmpeg version: 7.1-essentials_build-www.gyan.dev
  • OS: Windows

Code to reproduce

const fs = require('fs');
const ffmpeg = require('fluent-ffmpeg');
const Speaker = require('speaker');

let playing = false;
let ffmpegProcess = null;

function startPlaying(filePath) {
    if (playing) {
        console.log("Audio is already playing.");
        return;
    }

    console.log("Starting playback...");
    playing = true;

    ffmpegProcess = ffmpeg(filePath)
        .audioCodec('pcm_s16le')
        .audioFilters('volume=1')
        .format('wav')
        .pipe(new Speaker(), { end: false });

    ffmpegProcess.on('end', () => {
        console.log("Audio playback finished.");
        playing = false;
    });

    ffmpegProcess.on('error', (err) => {
        console.log("Error occurred during playback: ", err);
        playing = false;
    });
}

function stopPlaying() {
    if (!playing) {
        console.log("No audio is playing.");
        return;
    }

    console.log("Stopping playback...");
    playing = false;

    if (ffmpegProcess) {
        ffmpegProcess.kill('SIGSTOP');
        console.log("FFmpeg process killed.");
    }
}

const filePath = 'intro.mp3';

startPlaying(filePath);

setTimeout(() => {
    stopPlaying();
}, 5000);

Expected results

This should stop the audio, and continue the program.

Observed results

This should stop the audio, but results in a crash, that crashes the full program.

TypeError: ffmpegProcess.kill is not a function
at stopPlaying (C:\Users*\audioplayertest\app.js:44:23)
at Timeout._onTimeout (C:\Users*\audioplayertest\app.js:54:5)
at listOnTimeout (node:internal/timers:581:17)
at process.processTimers (node:internal/timers:519:7)

Node.js v20.17.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant