Function works first time, but not subsequent times

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • npm
    New Member
    • Apr 2007
    • 57

    #1

    Function works first time, but not subsequent times

    Hi,
    I'm trying to post song samples on a site and I've got a function that is supposed to detect whether the browser is IE (so it can embed Windows Media Player), supports mp3 in the HTML5 <audio> tag, or just embeds the mp3 for a plugin like QuickTime.

    The problem is that the function works fine for the first song sample, but doesn't when I call it for other songs. Here's the function:

    Code:
    function audioEmbed(targetDiv,fileName) {
    	var urlPath = "audio/";
    	
    	if (navigator.appName == "Microsoft Internet Explorer") {
    		document.getElementById(targetDiv).innerHTML = "<object id='Player' classid='CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6' codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715' standby='Loading Microsoft Windows Media Player components...' type='application/x-oleobject' width=180 height=45><param name='filename' value='" + urlPath + fileName + ".mp3'><param name='URL' value='" + urlPath + fileName + ".mp3'><param name='ShowPositionControls' value='0'><param name='ShowAudioControls' value='0'><param name='ShowTracker' value='0'><param name='AnimationAtStart' value='0'><param name='ShowDisplay' value='0'><param name='ShowStatusBar' value='0'><param name='AutoSize' value='0'><param name='DefaultFrame' value='datawindow'><param name='autostart' value='false'><embed type='application/x-mplayer2' src='" + urlPath + fileName + ".mp3' align='baseline' border='0' width='180' height='45' pluginspage='http://www.microsoft.com/isapi/redir.dll?prd=windows&amp;sbp=mediaplayer&amp;ar=media&amp;sba=plugin&amp;' name='MediaPlayer' ShowPositionControls='0' ShowAudioControls='0' ShowTracker='0' ShowDisplay='0' showstatusbar='0' autosize='0' AnimationAtStart='0' DefaultFrame='datawindow'></embed></object>";
    	}
    	else if (Modernizr.audio.mp3) {
    		document.getElementById(targetDiv).innerHTML = "<audio class='top30' controls src='" + urlPath + fileName + ".mp3'></audio>";
    	}
    	else {
    		document.getElementById(targetDiv).innerHTML = "<object width='180' height='16'><param name='src' value='" + urlPath + fileName + ".mp3'><param name='autoplay' value='false'><param name='controller' value='true'><embed src='" + urlPath + fileName + ".mp3' autostart='false' width='180' height='16' controller='true'></embed></object>";
    	}
    }
    And here's the sample html, etc.:

    Code:
    <div id="album">
    	<img src="img/albumcover1.jpg" />
    </div>
    <div id="tags">
    	Song:<br />
    	Artist:<br />
    	Album:
    </div>
    <div id="info">
    	Title 1<br />
    	Artist 1<br />
    	Album 1
    </div>
    <div id="audio">
    	<div id="audioSong1"></div>
    	<script type="text/javascript">
    		audioEmbed("audioSong1","Artist1 - SongTitle");
    	</script>
    </div>
    
    <div id="album">
    	<img src="img/albumcover2.jpg" />
    </div>
    <div id="tags">
    	Song:<br />
    	Artist:<br />
    	Album:
    </div>
    <div id="info">
    	Title 2<br />
    	Artist 2<br />
    	Album 2
    </div>
    <div id="audio">
    	<div id="audioSong2"></div>
    	<script type="text/javascript">
    		audioEmbed("audioSong2","Artist2 - SongTitle");
    	</script>
    </div>
    I'm getting the same results in IE9, FF6, Safari 5.1, Chrome 13, and Opera 11.5...the first song sample embeds/plays just fine, but the second one won't.

    Any help is appreciated, thanks!
Working...