2010-01-24 7 views
0

사용자가 서버의 일부 오디오 샘플을들을 수있게하기 위해 html5를 사용하는 응용 프로그램이 있습니다. 내가 서버에 실제 오디오 파일의 경로를 지정하는 경우, 상황이 예상대로 작동 :서블릿에서 생성 된 파일과 다르게 실제 파일을 처리하는 브라우저

<audio src="/audio/english/banana_1.mp3" controls> 
    Your browser does not support the <code>audio</code> element. 
</audio> 

을 그러나, 나는 오디오 파일을 생성하는 서블릿이 실제로 리소스를 가리키는 경우, 오디오하지 않습니다 재생하려고하는 것 같습니다 :

<audio src="/app/dbAudio" controls> 
    Your browser does not support the <code>audio</code> element. 
</audio> 

나는이 서블릿이 필요한 오디오 파일을 작성한다는 것을 확인했습니다. 다운로드하여 직접 재생했습니다. 나는 또한 audio/mpeg 및 audio/x-mpeg에 응답 contentType을 설정했지만 주사위는 사용하지 않았습니다. 이 작업을 수행하기 위해 설정해야하는 다른 헤더가 있습니까? 어떤 도움을 주셔서 감사합니다.

@RequestMapping(value = "/dbAudio", method = RequestMethod.GET) 
    public void getAudioFromDB(HttpServletRequest request, 
     HttpServletResponse response) throws Exception{ 

     response.setContentType("audio/mpeg"); 
     // Uncommenting the next allows me to download the resource directly and 
     // confirm that it is a well formed audio file 
     // response.setHeader("Content-disposition", "attachment; filename=banana.mp3"); 

     OutputStream o = response.getOutputStream(); 

     Resource r = ctx.getResources("/audio/english/banana_1.mp3")[0]; 
     InputStream s = r.getInputStream(); 

     int chunk = 0; 
     while(true){ 
      chunk = s.read(); 
      if(chunk == -1) break; 
      o.write(chunk); 
     } 
     o.flush();   
    } 
+1

두 요청의 응답 헤더를 가져와 비교하십시오. 붙어 있다면 질문에 추가하십시오. – BalusC

답변

1

시도해보십시오. snippet

+0

어, 왜 이것이 대신 작동 할 수 있는지 말할 수 있습니까? – BalusC

+1

전 전문가가 아니지만 콘텐츠 길이 때문에 어떨까요? http://www.w3.org/Protocols/HTTP/Object_Headers.html#content-length – JRL

+0

굉장한 내용으로 응답의 길이를 설정하는 링크입니다. 그게 내 문제를 해결해 줬어. 감사. –

관련 문제