2017-03-11 4 views
0

저는 AudioContext의 decodeAudioData 메소드를 사용하여 Chrome, Firefox 및 Opera에서 오디오를 재생합니다. 모든 브라우저는 Firefox를 사용하여 녹음 된 오디오를 성공적으로 디코딩하고 재생합니다. 그러나 오디오가 Chrome이나 Opera를 사용하여 녹음 된 경우 Firefox 만 성공적으로 디코딩하여 재생합니다. 내가 라디 Nevery의 수정 방법은 여기에 언급 구현하는 시도decodeAudioData - 오디오 데이터를 디코딩 할 수 없습니다.

Uncaught (in promise) DOMException: Unable to decode audio data.  

: 나는 크롬에서 오디오 나 오페라 디코딩 다음과 같은 오류 얻을 가 decodeAudioData returning a null error

구현 된 코드가 성공적으로 자신의 제안을 실행을 (버퍼를 통해 통과 오디오 스트림에서 시작 지점을 찾을 수는 있지만 Firefox에서 녹음 된 오디오의 경우 Chrome에서 여전히 디코딩이 실패합니다.

디코딩에 실패한 이유가 있습니까?

function syncStream(node){ // should be done by api itself. and hopefully will. 
     var buf8 = new Uint8Array(node.buf); 
     buf8.indexOf = Array.prototype.indexOf; 
     var i=node.sync, b=buf8; 
     while(1) { 
     node.retry++; 
     i=b.indexOf(0xFF,i); if(i==-1 || (b[i+1] & 0xE0 == 0xE0)) break; 
     i++; 
     } 
     if(i!=-1) { 
     var tmp=node.buf.slice(i); //carefull there it returns copy 
     delete(node.buf); node.buf=null; 
     node.buf=tmp; 
     node.sync=i; 
     return true; 
     } 
     return false; 
    } 

    export function loadAudio(deckId) { 
     store.audioPlayerDomain.audioLoading = true; 
     let activeRecord = getActiveRecordByDeckId(deckId); 
     let path = `${deckId}/${activeRecord.id}`; 
     let context = getAudioContext(); 
     let processFn = function(node){ 
     return context.decodeAudioData(node.buf, function (decoded) { 
      return decoded; 
      }, 
      function(){ // only on error attempt to sync on frame boundary 
      if(syncStream(node)){ 
       return processFn(node); 
      }; 
      }); 
     }; 
     return AudioPlayerWebAPI.default.getAudio(path, context) 
     .then((buffer) => { 
      let node = {}; 
      node.buf=buffer; 
      node.sync=0; 
      node.retry=0; 
      return processFn(node); 
     }).then(function(decodedData) { 
      store.audioPlayerDomain.audio = decodedData; 
      store.audioPlayerDomain.audioLoading = false; 
      return true; 
     }); 
    } 

    .... 

    getAudio(path, context) { 
    return fetch(`/api/public/audio/${path}`) 
     .then(processResponse) 
     .then(function(response) { 
     if(response.message && response.message === 'non-existent'){ 
      return null; 
     }else{ 
      return response.arrayBuffer(); 
     } 
     }) 
    }, 
+0

'.decodeAudioData (callbackFunction)'의 콜백 함수 버전에서 값을 반환하는 대신'.decodeAudioData(). then()'을 사용하지 않는 이유는 무엇입니까? 'callbackFunction'은 비동기입니다, 그렇습니까? – guest271314

+0

반대 방향에서이 문제를 해결할 가치가 없으며 Chrome이 다른 형식으로 기록하는 이유와 그 변경 방법을 알아 내겠습니까? 파일 포맷을 검사하기 위해'ffprobe '를 사용하고 싶을지도 모른다. ffmpeg 또는 클라우드 기반 솔루션 (여러 가지가 있음)을 사용하여 파일을 트랜스 코딩하여 항상 재생할 수 있는지 확인할 수도 있습니다. –

답변

2

아주 최근까지, decodeAudioData 크롬의 MediaRecorder의 결과를 디코딩 할 수있다. Chrome canary 또는 베타를 사용하여 문제가 해결되었는지 확인해보세요. 여전히 문제가 발생하면 작동하지 않는 것의보다 완전한 (그러나 간단한) 예를 제공하십시오.

+0

동일한 문제가 있었지만 [Chrome Canary] (https://www.google.co.uk/chrome/browser/canary.html)를 다운로드했는데 오류없이 작동합니다. –

+0

차가움. 다행이야! –

관련 문제