I want to enable the user to play a sound. My implementation works fine with firefox. On Safari the sound is not played. I verified, that the audio control works in safari with other websites. So, I assume, that I will have to change something in my controller?
Controller:
@RequestMapping(value = "/sound/character/get/{characterId}", method = RequestMethod.GET, produces = {
MediaType.APPLICATION_OCTET_STREAM_VALUE })
public ResponseEntity playAudio(HttpServletRequest request,HttpServletResponse response, @PathVariable("characterId") int characterId) throws FileNotFoundException{
logger.debug("[downloadRecipientFile]");
de.tki.chinese.entity.Character character = characterRepository.findById(characterId);
String file = UPLOADED_FOLDER + character.getSoundFile();
long length = new File(file).length();
InputStreamResource inputStreamResource = new InputStreamResource( new FileInputStream(file));
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setContentLength(length);
httpHeaders.setCacheControl(CacheControl.noCache().getHeaderValue());
return new ResponseEntity(inputStreamResource, httpHeaders, HttpStatus.OK);
}
View
<audio id="voice" controls="">
<source src="/sound/character/get/2">
</audio>