HTML5 오디오 플레이어로 작업하고 있습니다. 나는 재생 목록을 구현 중입니다. 다음 오디오 미디어 파일을 재생하기 위해 '종료 된'이벤트 동작을 사용하고 있습니다. 그러나 미디어 파일의 끝에서 '종료 됨'이벤트가 두 번 이상 발생합니다.HTML5 AudioPlayer 이벤트 동작 '종료 됨'이 두 번 이상 호출되고 있습니다.
//Event Listener
function addPlayerListener() {
console.log("Recording Index: "+combinedSessionIndex);
var audio = document.getElementById("playarea");
audio.addEventListener('ended', function() {
sessionsToPlay = $("#audio_files").val().split(',');
console.log ("In Recording End Event Listener...!!!"+combinedSessionIndex);
//It Shows Length '1' not '0'
if (sessionsToPlay.length == 1) {
console.log("Returned Due to Session To Play length..!!!")
return;
}
//As CombinedSessionIndex Starts with 1
if (combinedSessionIndex == sessionsToPlay.length) {
console.log("Returned Due to All Session To Play Got Finish..!!!")
$("#audio_files").val("");
sessionsToPlay = [];
combinedSessionIndex = 0;
return;
}
var filePath = '${properties["RECORDED_SESSION_RETREIVAL_PATH"]}';
filePath = filePath + sessionsToPlay[combinedSessionIndex] + ".mp4";
combinedSessionIndex++;
audio.src = filePath;
audio.play();
}, false);
}
그래서
, 특정 미디어 파일이 종료되면, 그 다음에 미디어 파일을 건너 뛰고 후 (다음 재생을 시작 : (. 내가 로그 메시지가 두 개 이상의 시간이 나타나는)
를이 내 이벤트 리스너입니다 1,2) 파일을 건너 뜁니다. 건너 뛴 미디어 파일마다 컨트롤은 이벤트 리스너에서 제공되며, 단일 호출이 끝나는 동안 이벤트 리스너가 반복적으로 호출 중임을 보여줍니다. 이 코드에 의해 오디오 파일을 재생할 처음
:
//PlayBack Session
function play(data) {
//Just to deal with a scenario that when we play a combined session and in the mean while we start listening any other single
//session, then after completion of this single session, remaining previous combined session should not resume.
//console.log("Re-setting Player ...!!!");
//$("#audio_files").val("");
//sessionsToPlay = [];
//combinedSessionIndex = 0;
var filePath = '${properties["RECORDED_SESSION_RETREIVAL_PATH"]}';
filePath = filePath + data + ".mp4";
console.log("filePath: " + filePath);
if (data == null || data == "") {
alert("Nothing to Play ...!!!");
return;
}
$("#playarea").attr({
"src": filePath,
"autoplay": "autoplay"
})
}
그리고이 종료, 더 클립입니다 재생하여 '종료'이벤트 리스너 후
.이유를 찾을 수 없습니다. 내가 틀린 일을하면 저를 안내해주십시오.
미리 감사드립니다. :)
이벤트 처리기를 변경하여'console.log ('ENDED event processed');를 호출하고 다른 모든 코드를 제거하는 코드가 한 줄만 있으면 여러 이벤트가 발생합니까? 예를 들어 오디오 파일을 찾을 수 없거나 매우 짧거나 다른 유사한 문제가있는 경우와 같이 이벤트 처리기에서 수행중인 작업으로 인해 새로운 종료 이벤트가 발생하는지 궁금합니다. – Fenton
하지만 다음 미디어 파일을 재생하기위한 코드는 그대로 남아 있습니까? –
그 코드를 사용하지 않고 여러 이벤트가 발생하는지 테스트해야하기 때문에 지금 당장 사용해보십시오. – Fenton