Search code examples
jqueryhtmlregexsoundmanager2

SoundManager / Jquery : Get SoundID sID


So I am trying to access a jquery soundmanager variable from one script (wpaudio.js – from the wp-audio plugin) inside of another (init.js – my own javascript). I am creating an alternate pause/play button higher up on the page and need to resume the current soundID, which is contained as part of a class name in the DOM.

Here is the code that creates that class name in wpaudio.js:

function wpaButtonCheck() {
if (!this.playState || this.paused)
    jQuery('#' + this.sID + '_play').attr('src', wpa_url + '/wpa_play.png');
else
    jQuery('#' + this.sID + '_play').attr('src', wpa_url + '/wpa_pause.png');

}

Here is the output:

<img src="http://24.232.185.173/wordpress/wp-content/plugins/wpaudio-mp3-player/wpa_play.png" class="wpa_play" id="wpa0_play">

where wpa0 would be the sID of the sound I need.

My current script in init.js is:

    $('.mixesSidebar #currentSong .playBtn').toggle(function() {
        soundManager.pauseAll();
        $(this).addClass('paused');
    }, function() {
        soundManager.resumeAll();
        $(this).removeClass('paused');
    });

I need to change resumeAll to "resume(this.sID)", but I need to somehow store the sID onclick and call it in the above function.

Alternately, I think a regular expression that could get the class name of the current play button and either parse the string up to the "_play" or use a trim function to get rid of "_play"– but I'm not sure how to do this.

Thanks for your help!


Solution

  • My solution was the following. Took out the string "+_play" in lines 33, 35, and 54 in wpaudio.js. Subsequently, the play button element for each mp3 has an ID attribute equal to it's soundmanager id. So I just created the following variable in my own .js:

    $('.mixPlayCell a').click( function() {
         var songsId = $(this).find('img').attr('id');
    });
    

    When you click on the mp3 , this stores the sID in the variable songsId

    I'd still like to know how to actually directly retrieve the sID without such a work-around...