J
J
jenya77712018-03-05 22:59:11
Node.js
jenya7771, 2018-03-05 22:59:11

Why is video stream not working in safari?

Hello, I'm transferring the video to the user via stream, everything works in chrome, but it doesn't work in safari.

fs.stat(pathFile, (err, stats) => {
        if (err) {

        // файл не найден
      } else {

        const { range } = req.headers;
        const { size } = stats;
        const start = Number((range || '').replace(/bytes=/, '').split('-')[0]);
        const end = size - 1;
        const chunkSize = (end - start) + 1;

        res.set({
          'Content-Range': `bytes ${start}-${end}/${size}`,
          'Accept-Ranges': 'bytes',
          'Content-Length': chunkSize,
          'Content-Type': 'video/mp4'
        });

        res.status(206);

        const stream = fs.createReadStream(pathFile, { start, end });
        stream.on('open', () => stream.pipe(res));
        stream.on('error', (streamErr) => res.end(streamErr));
      }
    })

What could be the problem?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question