我正在尝试创建自己的代码以使用媒体源播放实时 MPEG-DASH,我成功获取数据但无法在播放器中显示。
function GETData(){
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if(xhr.readyState == 4 && xhr.status == 200){
liveIndex++;
receiveBuffer.push(xhr.response);
if(audio == false){
appendVideo();
audio = true;
}
else{
appendAudio();
audio = false;
}
}
};
xhr.open("GET", urlList[liveIndex], true);
xhr.responseType = 'arraybuffer';
xhr.send();
}
function updateVideoFunc(){
sbVideo.removeEventListener("update", updateVideoFunc);
GETData();
}
function updateAudioFunc(){
sbAudio.removeEventListener("update", updateAudioFunc);
GETData();
}
function sourceopen(e){
sourceBuffer = this.sourceBuffers;
sourceBuffer[trackName] = ms.addSourceBuffer('video/mp4;codecs=avc1.42c01e');
sbVideo =sourceBuffer[trackName];
sbVideo.addEventListener('updateend', updateVideoFunc);
sourceBuffer = this.sourceBuffers;
sourceBuffer[trackName2] = ms.addSourceBuffer('audio/mp4;codecs="mp4a.40.2');
sbAudio =sourceBuffer[trackName2];
sbAudio.addEventListener('updateend', updateAudioFunc);
GETData();
}
var fileIndex = 0;
function appendVideo()
if(sbVideo.updating == false)
{
sbVideo.appendBuffer(new Uint8Array(receiveBuffer[fileIndex]));
sbVideo.addEventListener("updateend",updateVideoFunc, false);
fileIndex++;
}
}
function appendAudio(){
if(sbAudio.updating == false && sbVideo.updating == false){
sbAudio.appendBuffer(new Uint8Array(receiveBuffer[fileIndex]));
sbAudio.addEventListener("updateend",updateAudioFunc, false);
fileIndex++;
}
}
此代码在使用非实时源时有效,但不适用于实时代码。我错过了什么?