I want to create a html5 audioplayer for my band's website.
The audiofiles are stored in the database as mp3, ogg and wav files to support all major browsers on their current versions.
First, all audiofileversions for one audiofile are loaded into the html:
<audio class="song-preview" preload="none">
<source type="audio/ogg" src="/preview/trees/trees/OG/DT/OGG"></source>
<source type="audio/mpeg" src="/preview/trees/trees/OG/DT/MP3"></source>
<source type="audio/wav" src="/preview/trees/trees/OG/DT/WAV"></source>
</audio>
Method I:
Javascript checks with audio.canPlayType(type)
for browser support and removes all unsupported <source>
elements and adds a "probably"
source to the <audio>
's src
attribute.
Example I: (not working on my iphone).
Problem I:
Nested <source>
elements in an <audio>
element doesn't work well. (Altough Safari normally plays a given mp3 from an <audio>
's src
, it does not if it is in the <source>
's src
. Having big wav files in the sources prevents mobile devices from playing the audio, too.)
Method II:
Javascript checks with audio.canPlayType(type)
for browser support and adds the first "probably"-supported <source>
's src
to the <audio>
's src
attribute. After that all <source>
elements are removes.
Example II: (I am no JS expert but jsbin seems not to handle canPlayType() properly).
Problem II:
Safari classifys my ogg-files as "probably"
and then does not play them.
- Why is the audio from
<source>
elements not playing? - Any ideas on how to better check for audiotype browsersupport?
- Is having the same src in the
<audio>
element and the<source>
child normally working?