SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2010
    Posts
    93
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question How I play sound clip in mozilla...

    Code:
    <script>
    //function PlaySound() {   var sound = document.getElementById(sound1);  sound.Play();   alert("ok");}
    
    function playSound( url ){ 
      var s=document.getElementById("sound").innerHTML="<embed src='"+url+"' hidden=true autostart=true loop=false>";
      
      s.play();
    
    }
    </script>
    <!--
    <embed src="sound_5.mp3" hidden="true" autostart="false" loop="false" width="0" height="0" id="sound1" enablejavascript="true"/>-->
    <input type="button"  onclick="playSound('sound.wav')" value="Play"/>
    <div id="sound"></div>
    Hi friends,
    I want to play sound from above code which is working fine in IE and chrome browser but not works in mozilla firefox. It demands for some plugins and when I install the required plug-ins(Quick TIme), it neither works on mozilla and creates problem in chrome also (page covered with a blue screen.)
    So, friends can anyone tell me where I am wrong and what I should do now??
    Please help...
    Thanks in advance...

  2. #2
    SitePoint Member
    Join Date
    Feb 2012
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    dude instead of lengthy coding y dont you add html <audio></audio> tags man..this is much simpler..!!

  3. #3
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by surya D View Post
    dude instead of lengthy coding y dont you add html <audio></audio> tags man..this is much simpler..!!
    The <audio> tab may not be available though, which can cause browser problems.

    How to deal with that is to use the audio.js polyfill, which adds support for the <audio> tag even if it's not natively supported.

    For example:

    HTML Code:
    <script src="/audiojs/audio.min.js"></script>
    <script>
    audiojs.events.ready(function () {
        var as = audiojs.createAll();
    });
    </script>
    After that, you can use the <audio> tag and it will work, even if the browser doesn't support it.

    HTML Code:
    <audio src="sound_5.mp3" preload="auto" />
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  4. #4
    SitePoint Enthusiast
    Join Date
    Nov 2010
    Posts
    93
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paul_wilkins View Post
    The <audio> tab may not be available though, which can cause browser problems.

    How to deal with that is to use the audio.js polyfill, which adds support for the <audio> tag even if it's not natively supported.

    For example:

    HTML Code:
    <script src="/audiojs/audio.min.js"></script>
    <script>
    audiojs.events.ready(function () {
        var as = audiojs.createAll();
    });
    </script>
    After that, you can use the <audio> tag and it will work, even if the browser doesn't support it.

    HTML Code:
    <audio src="sound_5.mp3" preload="auto" />
    Thanks for reply...
    but I tried below code
    ------------------------------
    <html>
    <head>
    <script src="audiojs/audio.min.js"></script>
    <script>
    audiojs.events.ready(function () {
    var as = audiojs.createAll();
    });
    </script>
    </head>
    <body >
    <audio src="sound.mp3" preload="auto" />
    </body>
    </html>
    -----------------------------------------------
    but it not works at all in any browser. I can see the player image but there are no sound at all in any browser.
    I think <audio> and "preload" are attributes of HTML5 that's why it not works..
    but I am not sure about that.
    Can you please tell me what should I do now???
    Can you please tell where I am wrong??

  5. #5
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by ankit.pandeyc012 View Post
    but it not works at all in any browser
    Have you downloaded the what you need from the audio.js polyfill from their website?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  6. #6
    SitePoint Enthusiast
    Join Date
    Nov 2010
    Posts
    93
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paul_wilkins View Post
    Have you downloaded the what you need from the audio.js polyfill from their website?
    Yes sir...

  7. #7
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by ankit.pandeyc012 View Post
    Yes sir...
    That download comes with an example index.html file, that demonstrates things and provides details on how to achieve it.
    In that index.html file you should find that the audio file in there works for you, which will mean that the technique will be successful for you.

    If it works for you, we can then go further in to working out what's not going right for you.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  8. #8
    SitePoint Enthusiast
    Join Date
    Nov 2010
    Posts
    93
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paul_wilkins View Post
    That download comes with an example index.html file, that demonstrates things and provides details on how to achieve it.
    In that index.html file you should find that the audio file in there works for you, which will mean that the technique will be successful for you.

    If it works for you, we can then go further in to working out what's not going right for you.
    Sir, that index.html also not works...

  9. #9
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by ankit.pandeyc012 View Post
    Sir, that index.html also not works...
    What is the web browser & version that is not working with it?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  10. #10
    SitePoint Enthusiast
    Join Date
    Nov 2010
    Posts
    93
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Friends I got the following code
    ------------------------------------
    <audio controls>
    <source src="sound_5.ogg" type="audio/ogg"><!--firefox-->
    <source src="sound_5.mp3" type="audio/mpeg">
    <img dynsrc="sound_5.mp3" height=30 width=120 controls>
    </audio>
    -----------------------------------------

    Sir it works everywhere(mozila and chrome) but when I try to run same page via "localhost" (IIS Server) it works perfectly in chrome but stop working in mozilla..
    What is problem now???
    Please help...

  11. #11
    SitePoint Enthusiast
    Join Date
    Nov 2010
    Posts
    93
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks sir,
    it is working fine, I just configure IIS for "ogg" format and that's it.

    Thanks for everything..


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •