Results 1 to 10 of 10
  1. #1
    Join Date
    Aug 2006
    Location
    North Carolina
    Posts
    279
    Plugin Contributions
    0

    Default Play and pause so only one HTML5 audio element at a time plays on my website.

    Gang,

    I've got several HTML5 audio elements on a page. The play and pause functions work appropriately, but the tracks can all be played at the same time which is quite frustrating. The amount of audio elements varies with each search result. The audio elements run through a Function and access an additional field I created on my products_description table.

    Can anyone help me find a way to have all my audio element stop (or pause and go back to time=0) EXCEPT the one that the client clicks on?
    Do I need to add in javascript code directly within the function code below that will accomplished this? (or somewhere within another file...please direct me how to do that if that is the solution)

    Here is the function code I use that populates the advanced search page that uses HTML5 audio with fallback to Flash:

    PHP Code:
     function mp3_sample($prid) {
       global 
    $db;
       
    $firstdigit substr($prid0,1); 
       if ( (
    $firstdigit == 3) || ($firstdigit == 4) ) { 
          return 
    ''
       }
       
    $sample_query "select products_description5 
                       from products_description 
                       where products_id = '" 
    . (int)$prid"'"

        
    $sample $db->Execute($sample_query);

        if (
    $sample->RecordCount()) {
          if (
    trim($sample->fields['products_description5']) == '') return ''
          return 
    '<object><audio controls preload="auto" height="25px" width="300" ontimeupdate="updateTime()">
      <source src="' 
    $sample->fields['products_description5'] . '.ogg" type="audio/ogg">
      <source src="' 
    $sample->fields['products_description5'] . '.mp3" type="audio/mpeg">
      <embed height="25" width="300" src="' 
    $sample->fields['products_description5'] . '.mp3">
      </audio>
    <data="3523697345-audio-player.swf" type="application/x-shockwave-flash" width="300" height="27">
    <param name="src" value="3523697345-audio-player.swf" />
    <param name="FlashVars" value="audioUrl=' 
    $sample->fields['products_description5'] . '.mp3" />
    </object>'
    ;
        } else {
          return 
    '';
        }



    Here is a search result from my website that will demonstrate my problem:

    http://store1.musicalcreations.com/i...thousand+years

    thank you,
    Jeff Michaels,
    pres of Musical Creations Ltd.

  2. #2
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Play and pause so only one HTML5 audio element at a time plays on my website.

    1. Paste the following into a new file, and upload it to:
    /includes/templates/YOUR_TEMPLATE/jscript/jscript_mc_player_playpause.js
    Code:
    var currentPlayer;
    function pauseOthers(soundobj) {
      var thissound=document.getElementById(soundobj);
      if (currentPlayer && currentPlayer != thissound) {
        currentPlayer.pause(); 
      }
      if (thissound.paused) {
        thissound.play();
      } else {
        if (!thissound.play) thissound.pause();
        thissound.currentTime = 0;
        currentPlayer = thissound;
      }
    }
    2. Change your PHP code slightly:
    This line:
    Code:
          return '<object><audio controls preload="auto" height="25px" width="300" ontimeupdate="updateTime()">
    becomes
    Code:
          return '<object><audio controls preload="auto" height="25px" width="300" onplay="pauseOthers(\'audioclip' . $prid . '\');" id="audioclip' . $prid . '">
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  3. #3
    Join Date
    Aug 2006
    Location
    North Carolina
    Posts
    279
    Plugin Contributions
    0

    Default Re: Play and pause so only one HTML5 audio element at a time plays on my website.

    This looks like various code I've seen while searching the web for a solution but when I implemented it as you instructed, none of the other audio tracks that I'm playing stop when I start a new one.

    :-(
    Jeff Michaels,
    pres of Musical Creations Ltd.

  4. #4
    Join Date
    Aug 2006
    Location
    North Carolina
    Posts
    279
    Plugin Contributions
    0

    Default Re: Play and pause so only one HTML5 audio element at a time plays on my website.

    I got it.

    The updated code I received and copied from my email instead of this forum had 2 extra * in it... I took them out and PERFECTO!

    NO GOOD CODE BELOW I COPIED FROM MY EMAIL BY MISTAKE:
    return '<object><audio controls preload="auto" height="25px" width="300" *onplay="pauseOthers(\'audioclip' . $prid . '\');" id="audioclip' . $prid . '"*>

    THIS IS THE GOOD CODE YOU ORIGINALLY WROTE ABOVE:
    return '<object><audio controls preload="auto" height="25px" width="300" onplay="pauseOthers(\'audioclip' . $prid . '\');" id="audioclip' . $prid . '">
    Jeff Michaels,
    pres of Musical Creations Ltd.

  5. #5
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Play and pause so only one HTML5 audio element at a time plays on my website.

    Ya, the "bold" often gets denoted as * when translated into email notifications.

    It worked for me when I set up a test of it, so I'm glad you were able to get it working on your live site.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  6. #6
    Join Date
    Aug 2006
    Location
    North Carolina
    Posts
    279
    Plugin Contributions
    0

    Default Re: Play and pause so only one HTML5 audio element at a time plays on my website.

    Only problem I can find is this javascript will not work on the iPhone iPad. Multiple songs continue to play on that platform. 4 desktop browsers I've tested are good though.
    Jeff Michaels,
    pres of Musical Creations Ltd.

  7. #7
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Play and pause so only one HTML5 audio element at a time plays on my website.

    Hmmm, I didn't test iPad. Doh.

    But it did occur to me, and to accommodate it I was gonna offer a jQuery solution, but you're using such an old version of jQuery that compatibility becomes a problem ... and upgrading your other scripts which utilize jQuery requires some careful attention because the very next version after your older one changed some core behavior, causing some compatibility issues.

    I recall some articles suggesting that jPlayer was fairly reliable cross-platform and might be worth considering ... but again needs a more modern jQuery core to run against.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  8. #8
    Join Date
    Aug 2006
    Location
    North Carolina
    Posts
    279
    Plugin Contributions
    0

    Default Re: Play and pause so only one HTML5 audio element at a time plays on my website.

    I'll dig around in the future and figure out what exactly is utilizing jQuery on my website. Most of it was the 'disable after search' code you recently wrote and also the ajax-style searching that I trashed months ago. Is there other code within 1.5.1 that uses it internally?
    Jeff Michaels,
    pres of Musical Creations Ltd.

  9. #9
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Play and pause so only one HTML5 audio element at a time plays on my website.

    Quote Originally Posted by jeffmic View Post
    Is there other code within 1.5.1 that uses it internally?
    There is no jQuery built-in to v1.5.1
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  10. #10

    Default Re: Play and pause so only one HTML5 audio element at a time plays on my website.

    Ive just taken a quick look and it seems that when the page loads so does all the music as well, isn't this just wasting bandwidth if people aren't going to listen to them?

    Or am i wrong? im not sure

 

 

Similar Threads

  1. Adding JS Html5 Audio Player to Description
    By chriscana in forum General Questions
    Replies: 17
    Last Post: 15 Jun 2016, 02:11 PM
  2. v139h Nivo Slider Pause Time and Speed does not change
    By zc_fan in forum All Other Contributions/Addons
    Replies: 2
    Last Post: 25 Feb 2013, 12:50 AM
  3. Play audio clip on the product info page
    By Arunachala in forum General Questions
    Replies: 14
    Last Post: 19 Dec 2012, 11:57 AM
  4. v151 HTML5 Native Audio players?
    By Yolanda in forum General Questions
    Replies: 4
    Last Post: 12 Dec 2012, 08:37 PM
  5. Play an Audio, Sell a Document
    By alexalex in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 31 Aug 2006, 08:05 PM

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
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR