Uximy
Uximy

Reputation: 43

after restarting the page in the browser, the player stops loading

I have a problem which is that when I start icecast server on ubuntu and not only on ubuntu but also on windows regardless of the operating system, when I first go to the radio station in icecast2 http://localhost:8000/radio the music plays but after restarting the page in the browser, the player stops loading, I tried the solution with nocache in the browser in the address bar, nothing helps, I looked at many users configs, they did not encounter such problems, I will leave my config below, I also wrote a code on nodejs I will also leave it below, the problem plays the same that if I go to a direct icecast link, what I will do through the node js code + ffmpeg, also about the logs, nothing outputs even a hint of any error that is related to this problem

Config IceCast:

<icecast>
    <location>Earth</location>
    <admin>icemaster@localhost</admin>
    <hostname>localhost</hostname>

    <limits>
        <clients>100</clients>
        <sources>10</sources>
        <queue-size>524288</queue-size>
        <client-timeout>60</client-timeout>
        <header-timeout>30</header-timeout>
        <source-timeout>10</source-timeout>
        <burst-on-connect>1</burst-on-connect>
        <burst-size>65536</burst-size>
    </limits>

    <authentication>
        <source-password>hackme</source-password>
        <relay-password>hackme</relay-password>
        <admin-user>admin</admin-user>
        <admin-password>hackme</admin-password>
    </authentication>

    <listen-socket>
        <port>8000</port>
        <bind-address>0.0.0.0</bind-address>
    </listen-socket>
    
    <listen-socket>
        <port>8443</port>
        <bind-address>0.0.0.0</bind-address>
        <ssl>1</ssl>
    </listen-socket>

    <http-headers>
        <header name="Access-Control-Allow-Origin" value="*" />
        <header name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept" />
        <header name="Access-Control-Allow-Methods" value="GET, POST, OPTIONS" />
        <header name="Cache-Control" value="no-cache, no-store, must-revalidate" />
        <header name="Pragma" value="no-cache" />
        <header name="Expires" value="0" />
    </http-headers>

    
    <mount type="normal">
        <mount-name>/radio</mount-name>
        <password>mypassword</password>
        <public>1</public>
        <max-listeners>100</max-listeners>
        <stream-name>Anime Vibes</stream-name>
        <stream-description>Anime Vibes</stream-description>
        <genre>various</genre>
        <content-type>audio/ogg</content-type>
        <burst-size>65536</burst-size>
        
        <http-headers>
            <header name="Access-Control-Allow-Origin" value="*" />
            <header name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept" />
            <header name="Access-Control-Allow-Methods" value="GET, POST, OPTIONS" />
            <header name="Cache-Control" value="no-cache, no-store, must-revalidate" />
            <header name="Pragma" value="no-cache" />
            <header name="Expires" value="0" />
        </http-headers>
    </mount>

    <fileserve>1</fileserve>

    <paths>
        <logdir>/var/log/icecast2</logdir>
        <webroot>/etc/icecast2/web</webroot>
        <adminroot>/etc/icecast2/admin</adminroot>
       
        <alias source="/" destination="/status.xsl"/>
        
        <ssl-certificate>/etc/icecast2/cert/icecast.pem</ssl-certificate>
        
    </paths>

    <logging>
        <accesslog>access.log</accesslog>
        <errorlog>error.log</errorlog>
        <playlistlog>playlist.log</playlistlog>
        <loglevel>1</loglevel> <!-- 4 Debug, 3 Info, 2 Warn, 1 Error -->
        <logsize>10000</logsize> <!-- Max size of a logfile -->
        <logarchive>1</logarchive>
    </logging>
</icecast>

Code Node.js:

const express = require('express');
const { spawn } = require('child_process');
const path = require('path');
const fs = require('fs');
const https = require('https');
const app = express();
const port = 3000;

const privateKey = fs.readFileSync('./cert/privateKey.key', 'utf8');
const certificate = fs.readFileSync('./cert/certificate.crt', 'utf8');

const credentials = {
    key: privateKey,
    cert: certificate
};

app.use(express.static(path.join(__dirname)));

// Check if playlist file exists
const playlistPath = path.join(__dirname, 'playlist.txt');
if (!fs.existsSync(playlistPath)) {
    console.error('Playlist file does not exist');
    process.exit(1);
}

console.log(`Playlist path: ${playlistPath}`);

// Start FFmpeg process to create continuous stream from playlist
const ffmpegProcess = spawn('ffmpeg', [
    '-re',
    '-f', 'concat',
    '-safe', '0',
    '-protocol_whitelist', 'file,http,https,tcp,tls',
    '-i', playlistPath,
    '-c:a', 'libvorbis',
    '-f', 'ogg',
    '-tls', '1',
    'icecast://source:mypassword@localhost:8443/radio'
]);

ffmpegProcess.stdout.on('data', (data) => {
    console.log(`FFmpeg stdout: ${data}`);
});

ffmpegProcess.stderr.on('data', (data) => {
    console.error(`FFmpeg stderr: ${data}`);
});

ffmpegProcess.on('close', (code) => {
    console.log(`FFmpeg process exited with code ${code}`);
});

app.get('/radio', (req, res) => {
    res.setHeader('Content-Type', 'audio/ogg');
    res.setHeader('Transfer-Encoding', 'chunked');

    const requestOptions = {
        hostname: 'localhost',
        port: 8443,
        path: '/radio',
        method: 'GET',
        headers: {
            'Accept': 'audio/ogg'
        },
        rejectUnauthorized: false
    };

    const request = https.request(requestOptions, (response) => {
        response.pipe(res);

        response.on('end', () => {
            res.end();
        });
    });

    request.on('error', (err) => {
        console.error(`Request error: ${err.message}`);
        res.status(500).send('Internal Server Error');
    });

    request.end();
});
https.globalAgent.options.ca = [certificate];
// Create HTTPS server
const httpsServer = https.createServer(credentials, app);

httpsServer.listen(port, () => {
    console.log(`Server is running at https://localhost:${port}`);
});

I hope for your help and any advice, thanks in advance

Upvotes: 0

Views: 35

Answers (1)

Uximy
Uximy

Reputation: 43

The problem was closed with the solution it turned out that Icecast I put the content type audio/ogg And in the code FFmpeg there was no content type and it defaults to content audio/mpeg This is why the content mix happened, thanks to everyone who answered the problem

Upvotes: 0

Related Questions