私のnodejsサーバから提供されているSafariでmp4ビデオファイルを読み込む際に問題があります。この問題はChromeには存在しません。nodejsサーバが提供するSafariでmp4ビデオを再生できません
問題を説明するために、私はw3schoolsから提供されたmp4ファイルmov_bbb.mp4
を読み込む簡単なhtmlウェブページを持っています。私は同じファイルをダウンロードし、nodejsサーバーから提供します。
vid1
(w3schoolsから提供)は、ChromeとSafariの両方でうまく読み込みます。
vid2
(私のnodejsサーバーから提供されます)はSafariではなくChromeでは正常に読み込みます。ここで
は私がChromeで見るもののスクリーンショットです:
ここで私はSafariで見るもののスクリーンショットです:ここで
は私のhtmlです:
<!DOCTYPE html>
<html>
<head>
<title>test</title>
</head>
<body>
<video id="vid1" controls preload="auto" src="https://www.w3schools.com/html/mov_bbb.mp4"></video>
<video id="vid2" controls preload="auto" src="http://localhost:8125/mov_bbb.mp4"></video>
</body>
</html>
ここに私のnodejsサーバです:
var http = require('http');
var fs = require('fs');
var path = require('path');
http.createServer(function (request, response) {
console.log('request starting...');
var filePath = '.' + request.url;
if (filePath == './')
filePath = './index.html';
var extname = path.extname(filePath);
var contentType = 'video/mp4';
fs.readFile(filePath, function(error, content) {
if (error) {
if(error.code == 'ENOENT'){
fs.readFile('./404.html', function(error, content) {
response.writeHead(200, { 'Content-Type': contentType });
response.end(content, 'utf-8');
});
}
else {
response.writeHead(500);
response.end('Sorry, check with the site admin for error: '+error.code+' ..\n');
response.end();
}
}
else {
response.writeHead(200, {
});
response.end(content, 'utf-8');
}
});
}).listen(8125);
console.log('Server running at http://127.0.0.1:8125/');
私は何か提案が大歓迎です。
更新:
改訂nodejsコード。しかしサファリでも同じ問題:
var http = require('http');
var fs = require('fs');
http.createServer(function (request, response) {
console.log('request starting...');
var filePath = '.' + request.url;
if (filePath == './') {
var contentType = 'text/html';
filePath = './index.html';
} else {
var contentType = 'video/mp4';
}
var rstream = fs.createReadStream(filePath);
rstream.on('error', function(error) {
response.writeHead(404);
response.end();
});
rstream.on('open', function() {
response.writeHead(200, {
'Content-Type': contentType,
});
});
rstream.pipe(response);
}).listen(8125);
console.log('Server running at http://127.0.0.1:8125/');
また、HTTPヘッダーのためのクロムインスペクタ:
@stthoms ...私は同じ問題に直面しています...サファリで作業していません...あなたは修正を見つけるか...もしそうなら、それを共有することができます.. – dev9