Toggling between instances of NiftyPlayer on a page - won't stop playing when hidden on IE

Posted by Ashley on Stack Overflow See other posts from Stack Overflow or by Ashley
Published on 2009-11-30T17:44:28Z Indexed on 2010/04/07 17:03 UTC
Read the original article Hit count: 310

Filed under:
|

Hi, i've got a page with links to MP3s, when the link is clicked I use javascript to show a small Flash player (NiftyPlayer) under the link. When a different link is clicked, the old player is hidden and the new player is revealed.

The player auto-starts when the element is shown, and auto-stops when hidden - in Firefox.

In IE it will only auto-start and NOT auto-stop. This is what I would like to solve.

This is an example HTML with link and player

<a href="Beat The Radar - Misunderstood What You Said.mp3" onclick="toggle_visibility('player662431');return false;" class="mp3caption">Misunderstood What You Said</a>

<div id="player662431" class="playerhide"><embed src="http://www.xxx.com/shop/flash/player.swf?file=/mp3/Beat The Radar - Misunderstood What You Said.mp3&as=1" quality="high" bgcolor="#000000" width="161" height="13" name="niftyPlayer662431" align="" type="application/x-shockwave-flash" swLiveConnect="true" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>

Here is the javascript (i've got jquery installed to let me hide all the open players on this page apart from the new one)

function toggle_visibility(id) {
 $('.playerhide').hide();
 var e = document.getElementById(id);
 e.style.display = 'block';
}

I think what I need to do is start the player manually with javascript (rather than using the autostart as=1 function in the URL string)

There is some javascript that comes with NiftyPlayer to allow this EG

niftyplayer('niftyPlayer1').play()

there is also a stop method.

I need some help with javascript - how do I add this call to play into my toggle_visibility function (it has the same unique ID number added to the name of the player as the ID of the div that's being shown, but I don't know how to pull this ID number out of one thing and put it in another)

I also would like to be able to do

niftyplayer('niftyPlayer1').stop()

to stop the audio of the previously running player. Is it possible to store the current ID number somewhere and call it back when needed?

Thanks for the help, i'm a PHP programmer who needs some support with Javascript - I know what I want to achieve, just don't know the commands to do it!

Thanks

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery