MediaSourceを使って再生しようとしているビデオが2つありますが、そのうちの1つのみが動作します。どちらもコーデックはavc1.4d401fとmp4a.40.2に設定されていますが、一方がうまくいくうちにもう一方がSourceBufferのappendBufferを呼び出すとすぐにMediaSourceを閉じます。次のようにコードの関連ビットは、次のとおりappendBufferの後でMediaSourceが閉じた
var mainSource;
var mimeCoded = 'video/mp4; codecs="avc1.4d401f,mp4a.40.2"';
mainSource = new MediaSource();
var sourceBuffer;
mainSource.addEventListener('sourceopen',() => {
console.log('readystate', mainSource.readyState);
var xhr = new XMLHttpRequest();
xhr.responseType = 'arraybuffer';
xhr.open('get', 'main.mp4');
xhr.addEventListener('load', (e) => {
sourceBuffer = mainSource.addSourceBuffer(mimeCoded);
sourceBuffer.mode = 'sequence';
sourceBuffer.addEventListener('updateend', onUpdateEnd);
sourceBuffer.appendBuffer(e.target.response);
console.log('updating', sourceBuffer.updating);
});
xhr.send();
});
vid.src = URL.createObjectURL(mainSource);
onUpdateEnd = function()
{
console.log('readystate2', mainSource.readyState, sourceBuffer.updating);
vid.play();
sourceBuffer.removeEventListener('updateend', onUpdateEnd);
};
mainSource.readyState
意志出力open
で動画の一方、両方のログを使用したが、別のものと、第2ログ(及びvid.play()
に結果としてエラー)にclosed
を示します。私はすでに何が起こっているかもしれないかについてのアイデアがないので、どんな助けもありがたいです。