change src of embed using JS

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • helraizer1
    New Member
    • Mar 2007
    • 118

    change src of embed using JS

    I have this code in JS

    [code=javascript]
    function show_player() {
    document.mediap layer1.style.vi sibility = "visible";
    }
    function content(p, clip) {
    var mus = document.getEle mentById('music ');

    mus.style.visib ility = "visible";
    mus.innerHTML = p;

    var sound = [];

    sound['ocean'] = "./Ocean_Breeze.mp 3";
    sound['always'] = "http://www.youtube.com/v/K9MFBuzr6p4&rel =1";
    sound['day'] = "http://www.youtube.com/v/Wxx_rO2oLPE&rel =1";
    sound['mid'] = "http://www.youtube.com/v/4qQ4fpTBHwI&rel =1";
    sound['erupt'] = "http://www.youtube.com/v/tqhz-i1WIQo&rel=1";

    document.mediap layer1.src = sound[clip];

    }
    [/code]

    with the following HTML to go with it.

    [code=html]
    <table align="center">
    <tr>
    <td colspan="1"><p style="visibili ty:hidden;" id="music">Ocea n Breeze</p></td>
    </tr>
    <tr>
    <td colspan="1"><em bed type="applicati on/x-mplayer2" pluginspage="ht tp://www.microsoft.c om/Windows/MediaPlayer/" name="mediaplay er1" showstatusbar=" 1" id="mp" EnableContextMe nu="false" autostart="fals e" width="630" height="70" transparentstar t="1" loop="0" controller="tru e" src="" style="visibili ty:hidden;"></embed></td>
    </tr>
    </table>
    </td></tr></table>
    <br><br><br>
    <table align="center">
    <tr>
    <td align="center" colspan="1"><p> Which song would you like to hear?</p></td></tr>
    <tr>
    <td>
    <a href="#" onclick="javasc ript:show_playe r();content('Oc ean Breeze','ocean' );"> Ocean Breeze</a>
    </td>
    <td>|</td>
    </tr>
    <tr>
    <td>
    <a href="#" onclick="javasc ript:show_playe r();content('Al ways with me, always with you','always'); ">Always With Me, Always With You</a>
    </td>
    <td>|</td>
    </tr>
    <tr>
    <td>
    <a href="#" onclick="javasc ript:show_playe r();content('Da y at the Beach','day');" >Day Of The Beach</a>
    </td>
    <td>|</td>
    </tr>
    <tr>
    <td>
    <a href="#" onclick="javasc ript:show_playe r();content('Mi dnight','mid'); ">Midnight</a>
    </td>
    <td>|</td>
    </tr>
    <tr>
    <td>
    <a href="#" onclick="javasc ript:show_playe r();content('Er uption', 'erupt');">Erup tion</a>
    </td>
    <td>|</td>
    </tr>
    </table>
    [/code]

    When I click the links the player appears, so the visibility part works, also the innerHTML of the <p> element works on each, but the content doesn't change, is there something I'm doing wrong?

    Sam
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Do you get any errors?

    Comment

    • helraizer1
      New Member
      • Mar 2007
      • 118

      #3
      Originally posted by acoder
      Do you get any errors?
      No errors, it simply wouldn't play the media but now I've fixed it, I changed it to:

      [code=javascript]
      function play(desc) {


      var sound = [];

      sound['ocean'] = '<embed type="applicati on/x-mplayer2" pluginspage="ht tp://www.microsoft.c om/Windows/MediaPlayer/" name="mediaplay er1" showstatusbar=" 1" EnableContextMe nu="false" autostart="true " width="400" height="400" transparentstar t="1" loop="0" controller="tru e" src="./Ocean_Breeze.mp 3" style=" border:1 #fff;"></embed>';

      sound['always'] = '<embed type="applicati on/x-mplayer2" pluginspage="ht tp://www.microsoft.c om/Windows/MediaPlayer/" name="mediaplay er1" showstatusbar=" 1" EnableContextMe nu="false" autostart="true " width="400" height="400" transparentstar t="1" loop="0" controller="tru e" src="always.mp3 " style=" border:1 #fff;"></embed>';

      sound['day'] = '<embed type="applicati on/x-mplayer2" pluginspage="ht tp://www.microsoft.c om/Windows/MediaPlayer/" name="mediaplay er1" showstatusbar=" 1" EnableContextMe nu="false" autostart="true " width="400" height="400" transparentstar t="1" loop="0" controller="tru e" src="day at the beach.mp3" style=" border:1 #fff;"></embed>';

      sound['mid'] = '<embed type="applicati on/x-mplayer2" pluginspage="ht tp://www.microsoft.c om/Windows/MediaPlayer/" name="mediaplay er1" showstatusbar=" 1" EnableContextMe nu="false" autostart="true " width="400" height="400" transparentstar t="1" loop="0" controller="tru e" src="Midnight.m p3" style=" border:1 #fff;"></embed>';

      sound['erupt'] = '<embed type="applicati on/x-mplayer2" pluginspage="ht tp://www.microsoft.c om/Windows/MediaPlayer/" name="mediaplay er1" showstatusbar=" 1" EnableContextMe nu="false" autostart="true " width="400" height="400" transparentstar t="1" loop="0" controller="tru e" src="eruption.m p3" style=" border:1 #fff;"></embed>';

      document.getEle mentById('playe r').innerHTML = sound[desc];
      }[/code]

      with player being -
      Code:
      <td colspan="1" ><div id="player"></div></td>
      It works now.

      Sam

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Well, that would work, but it seems a bit overkill to replace the whole object each time just to change the source. Anyway, since there's only 5 options, it's not too bad.

        Comment

        Working...