470,596 Members | 1,594 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,596 developers. It's quick & easy.

change src of embed using JS

118 100+
I have this code in JS

Expand|Select|Wrap|Line Numbers
  1.     function show_player() {
  2.         document.mediaplayer1.style.visibility = "visible";
  3.     }
  4.     function content(p, clip) {
  5.         var mus = document.getElementById('music');
  6.  
  7.         mus.style.visibility = "visible";
  8.         mus.innerHTML = p;
  9.  
  10.             var sound = [];
  11.  
  12.         sound['ocean'] = "./Ocean_Breeze.mp3";
  13.         sound['always'] = "http://www.youtube.com/v/K9MFBuzr6p4&rel=1";
  14.         sound['day'] = "http://www.youtube.com/v/Wxx_rO2oLPE&rel=1";
  15.         sound['mid'] = "http://www.youtube.com/v/4qQ4fpTBHwI&rel=1";
  16.         sound['erupt'] = "http://www.youtube.com/v/tqhz-i1WIQo&rel=1";
  17.  
  18.         document.mediaplayer1.src = sound[clip];
  19.  
  20.     }
  21.  
with the following HTML to go with it.

Expand|Select|Wrap|Line Numbers
  1. <table align="center">
  2. <tr>
  3. <td colspan="1"><p style="visibility:hidden;" id="music">Ocean Breeze</p></td>
  4. </tr>
  5. <tr>
  6. <td colspan="1"><embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" name="mediaplayer1" showstatusbar="1" id="mp" EnableContextMenu="false" autostart="false"  width="630" height="70"  transparentstart="1" loop="0" controller="true" src="" style="visibility:hidden;"></embed></td>
  7. </tr>
  8. </table>
  9. </td></tr></table>
  10. <br><br><br>
  11. <table align="center">
  12. <tr>
  13. <td align="center" colspan="1"><p>Which song would you like to hear?</p></td></tr>
  14. <tr>
  15. <td>
  16. <a href="#" onclick="javascript:show_player();content('Ocean Breeze','ocean');"> Ocean Breeze</a>
  17. </td>
  18. <td>|</td>
  19. </tr>
  20. <tr>
  21. <td>
  22. <a href="#" onclick="javascript:show_player();content('Always with me, always with you','always');">Always With Me, Always With You</a>
  23. </td>
  24. <td>|</td>
  25. </tr>
  26. <tr>
  27. <td>
  28. <a href="#" onclick="javascript:show_player();content('Day at the Beach','day');">Day Of The Beach</a>
  29. </td>
  30. <td>|</td>
  31. </tr>
  32. <tr>
  33. <td>
  34. <a href="#"  onclick="javascript:show_player();content('Midnight','mid');">Midnight</a>
  35. </td>
  36. <td>|</td>
  37. </tr>
  38. <tr>
  39. <td>
  40. <a href="#" onclick="javascript:show_player();content('Eruption', 'erupt');">Eruption</a>
  41. </td>
  42. <td>|</td>
  43. </tr>
  44. </table>
  45.  
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
Feb 14 '08 #1
3 3025
acoder
16,027 Expert Mod 8TB
Do you get any errors?
Feb 16 '08 #2
helraizer1
118 100+
Do you get any errors?
No errors, it simply wouldn't play the media but now I've fixed it, I changed it to:

Expand|Select|Wrap|Line Numbers
  1. function play(desc) {
  2.  
  3.  
  4.         var sound = [];
  5.  
  6.         sound['ocean'] = '<embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" name="mediaplayer1" showstatusbar="1" EnableContextMenu="false"  autostart="true"  width="400" height="400"  transparentstart="1" loop="0" controller="true" src="./Ocean_Breeze.mp3"  style=" border:1 #fff;"></embed>';
  7.  
  8.         sound['always'] = '<embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" name="mediaplayer1" showstatusbar="1" EnableContextMenu="false"  autostart="true"  width="400" height="400"  transparentstart="1" loop="0" controller="true" src="always.mp3"  style=" border:1 #fff;"></embed>';
  9.  
  10.         sound['day'] = '<embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" name="mediaplayer1" showstatusbar="1" EnableContextMenu="false"  autostart="true"  width="400" height="400"  transparentstart="1" loop="0" controller="true" src="day at the beach.mp3"  style=" border:1 #fff;"></embed>';
  11.  
  12.         sound['mid'] = '<embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" name="mediaplayer1" showstatusbar="1" EnableContextMenu="false"  autostart="true"  width="400" height="400"  transparentstart="1" loop="0" controller="true" src="Midnight.mp3"  style=" border:1 #fff;"></embed>';
  13.  
  14.         sound['erupt'] = '<embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" name="mediaplayer1" showstatusbar="1" EnableContextMenu="false"  autostart="true"  width="400" height="400"  transparentstart="1" loop="0" controller="true" src="eruption.mp3"  style=" border:1 #fff;"></embed>';
  15.  
  16.         document.getElementById('player').innerHTML = sound[desc];
  17.         }
with player being -
Expand|Select|Wrap|Line Numbers
  1. <td colspan="1" ><div id="player"></div></td>
  2.  
It works now.

Sam
Feb 16 '08 #3
acoder
16,027 Expert Mod 8TB
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.
Feb 16 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

11 posts views Thread by Anna | last post: by
15 posts views Thread by Encapsulin | last post: by
1 post views Thread by richardscheff | last post: by
1 post views Thread by Andrew Poulos | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.