Due to HTML5 browser formats tricks I have to put fallback audio formats also in audio format. I want to set the src of source in audio programmatically but it is not working.
This is my HTML code:
<audio id=audioPlayer width=400 height=30 controls=controls>
<source id=oggSource type=audio/ogg />
<source id=mp3Source type=audio/mp3 />
</audio>
Then in javascript using jquery I set the source for each of them (I have one audio tag and many mp3 on page and based on some event I want to change the source of audio tag) so I can't specify src directly in audio mainly because I need fallback support and also I need dynamism.
Using jquery I manipulate the src:
$('#oggSource').attr('src', 'OggFormat.ogg');
$('#mp3Source').attr('src','Mp3Format.mp3');
But this however doesn't work. Any idea why?
If I use:
<audio id=audioPlayer width=400 height=30 controls=controls>
<source id=oggSource type=audio/ogg src=OggFormat.ogg />
<source id=mp3Source type=audio/mp3 src=Mp3Format.mp3/>
</audio>
it works but as I need I need to set it in code and not provide statically.