Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #17797

Re: html5 Audio

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail
From 123Jim <jnkjnjnini@uhnuhnunuhnuy.invalid>
Newsgroups comp.lang.javascript
Subject Re: html5 Audio
Date Sat, 22 Dec 2012 13:31:07 +0000
Organization A noiseless patient Spider
Lines 57
Message-ID <kb4cn3$csc$1@dont-email.me> (permalink)
References <kb2s2r$ihs$1@dont-email.me> <q66dnaeG-5ZHn0jNnZ2dnUVZ_r-dnZ2d@westnet.com.au>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
Injection-Date Sat, 22 Dec 2012 13:31:15 +0000 (UTC)
Injection-Info mx04.eternal-september.org; posting-host="3c143e683a5921d27416b2622ab6eb29"; logging-data="13196"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Vtt2z9JJmcg5DAe4R6CGQ"
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/17.0 Thunderbird/17.0
In-Reply-To <q66dnaeG-5ZHn0jNnZ2dnUVZ_r-dnZ2d@westnet.com.au>
Cancel-Lock sha1:BZ6yek4hSliLei4bxlDG2o0Ms5w=
Xref csiph.com comp.lang.javascript:17797

Show key headers only | View raw


On 22/12/2012 00:46, Andrew Poulos wrote:
> On 22/12/2012 10:41 AM, 123Jim wrote:
>> Q: Is the html5 Audio code below cross browser and robust? It occurs to
>> me that if the browser does not like 'canplaytype' but nevertheless
>> needs ogg, not MP3 then it will fail (I've tested in the newest versions
>> of IE, Firefox, Opera and Chrome with no problems)
>>
>> var audio1 = new Audio();
>>
>> if (!!audio1.canPlayType && audio1.canPlayType('audio/ogg;
>> codecs="vorbis"') != "") {
>>      //alert('ogg sounds');
>>      var    click1snd = new Audio("click1.ogg");
>>      var    incorrectsnd = new Audio("incorrect.ogg");
>>      var    correctsnd = new Audio("correct.ogg");
>> }else{
>>      //alert('mp3 sounds');
>>      var    click1snd = new Audio("click1.mp3");
>>      var    incorrectsnd = new Audio("incorrect.mp3");
>>      var    correctsnd = new Audio("correct.mp3");
>> }
>>
>>      click1snd.play();
>
> Wouldn't it be better to add an audio element
>
> <audio id="click1">
>    <source src="click1.ogg" type="audio/ogg">
>    <source src="click1.mp3" type="audio/mp3">
> </audio>
>
> to the page and then call
>
> document.getElementById("click1").play();
>
> to the page and let browsers sort out which one it can play?
>
> Also what are you going to do about browsers that don't support the
> audio element?
>
> Andrew Poulos


Thanks Andrew, That seem like a better way to add audio to my webpage.

For browsers that don't support the Audio element this looks like the 
way to go: http://www.brandaiddesignco.com/blog/html5-audio-made-easy/104/

So the audio element now looks like this:
<audio id="click1snd">
     <source src="click1.ogg" type="audio/ogg">
     <source src="click1.mp3" type="audio/mp3">
     <embed src="click1.mp3" hidden="true" />
  </audio>

I'll need to dig out an old XP computer to test it though.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

html5 Audio 123Jim <jnkjnjnini@uhnuhnunuhnuy.invalid> - 2012-12-21 23:41 +0000
  Re: html5 Audio Andrew Poulos <ap_prog@hotmail.com> - 2012-12-22 11:46 +1100
    Re: html5 Audio 123Jim <jnkjnjnini@uhnuhnunuhnuy.invalid> - 2012-12-22 13:31 +0000
      Re: html5 Audio 123Jim <jnkjnjnini@uhnuhnunuhnuy.invalid> - 2012-12-22 16:33 +0000
        Re: html5 Audio 123Jim <jnkjnjnini@uhnuhnunuhnuy.invalid> - 2012-12-22 23:16 +0000
          Re: html5 Audio David Mark <dmark.cinsoft@gmail.com> - 2013-01-05 17:54 -0800
            Re: html5 Audio David Mark <dmark.cinsoft@gmail.com> - 2013-01-05 18:06 -0800
            Re: html5 Audio David Mark <dmark.cinsoft@gmail.com> - 2013-01-05 23:18 -0800

csiph-web