473,473 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

change src of embed using JS

118 New Member
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 3124
acoder
16,027 Recognized Expert Moderator MVP
Do you get any errors?
Feb 16 '08 #2
helraizer1
118 New Member
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 Recognized Expert Moderator MVP
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

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

Similar topics

11
by: Anna | last post by:
Hi all. I want to embed the EMBED tag in the object tag. I understood that I need to provide a PARAM tag inside the OBJECT whose value will hold the content of EMBED src attribute, but after...
15
by: Encapsulin | last post by:
Hello everybody. I'm trying to change src of quicktime embedded object with javascript: <html><body> <script language="JavaScript"> function Exchange() { document.qtvr.src = "sample2.pano";...
1
by: richardscheff | last post by:
Video selector works for IE but not other browsers. for not IE <object ID='Player' data="video/dodgeball.wmv" type="video/x-ms-wmv" width="320" height="280"> <param name="filename"...
1
by: Andrew Poulos | last post by:
With "normal" SWF HTML there's an EMBED tag nested within an OBJECT tag. How can I check which tag is actually displaying the SWF? I'm using CSS on them and the style on the OBJECT affects the...
3
by: synergy_711 | last post by:
I feel like this should be fairly easy but I have been struggling with this for sometime. I have not been able to find someone who's had the same problem as mine yet. ...
5
by: austincollins | last post by:
I have been searching for hours to find a solution to display text rotated at 90 degrees in firefox, and could not find one. css3 and IE has the css command "writing-mode: tb-rl;" but this does not...
5
by: elbin | last post by:
Hello, first to say that I am a total beginner in Javascript but I know some programming (python in particular) and am able to understand methods/parameters and so on. Here's my problem: I am...
2
dream party
by: dream party | last post by:
Inserting a Flash (SWF, FLV) file into HTML web page is already an old and familiar thing to all of us. It is a rather non-flexible thing that just to edit some options in the template. However, I...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.