Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.

.kill is not a function #1311

@JulianAa14

Description

@JulianAa14

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions