PDA

View Full Version : Video Player in Switch Content Script II



videoguy
03-15-2008, 04:15 PM
1) Script Title: Switch Content Script II

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex17/switchcontent2.htm

3) Describe problem: I want to use your script to display a small collection of videos on my web site. Putting the players in a <div>'s was simple but I have one nagging problem. If a viewer starts playing a video and then selects a different Tab. The old one closes and the new one opens fine but the video from the now closed tab continues to play and the audio can still be heard.

The player has a javascript API and comes with a FUNCTION to stop a video playing.

I've poked around in both switchicon.js and switchcontent.js and tried to add the function but I'm just not smart enough to figure out where to place the code.

If someone here knows how to do what I want could you please tell me where to put both the function itself and the call that fires it. Here is the function:

<script type="text/javascript">
function sendEvent(swf,typ,prm) {
thisMovie(swf).sendEvent(typ,prm);
};
function getUpdate(typ,pr1,pr2,swf) {};
function thisMovie(swf) {
if(navigator.appName.indexOf("Microsoft") != -1) {
return window[swf];
} else {
return document[swf];
}
};
</script>


And this is how they say it should be called:

javascript:sendEvent('player1','stop')

The sad truth is I don't know where to put either piece of code.

Thanks - Videoguy

ddadmin
03-16-2008, 04:02 AM
Hmmm please clarify which script you're referencing, as you linked to "Tab Content script", yet talked about switchcontent.js, which is for another script...

videoguy
03-16-2008, 02:36 PM
Thanks for pointing out my error. The script I am actually trying to modify and use is switch content 2

ddadmin
03-17-2008, 12:02 AM
Sure, the logic is to call:


sendEvent('player1','stop')

each time a content is closed, with some way to specify the ID of the player (I presume the code in red above) that's associated with different headers. With that in mind, firstly, inside your containers used as the icon togglers, specify a title attribute pointing to the ID of the video player its sub content is carrying, for example:


<div class="eg-bar"><span id="faq1-title" title="video1" class="iconspan"><img src="minus.gif" /></span>What is JavaScript?</div>
<div id="faq1" class="icongroup1">
JavaScript is a scripting language originally developed by Netscape to add interactivity and power to web documents. It is purely client side, and runs completely on the client's browser and computer.
</div>
<br />

<div class="eg-bar""><span id="faq2-title" title="video2" class="iconspan"><img src="minus.gif" /></span>Difference between Java & JavaScript?</div>
<div id="faq2" class="icongroup1">
Java is completely different from JavaScript- the former is a compiled language while the later is a scripting language.
</div>
<br />

So closing the first header should also call your custom function to stop the player with ID="video1". To do this, inside statusicon.js, make the changes in red below:


switchicon.prototype.contractcontent=function(header){
var innercontent=document.getElementById(header.id.replace("-title", "")) //Reference content for this header
innercontent.style.display="none"
header.innerHTML=this.closeHTML
sendEvent(header.title,'stop')
header=null
}

This only works provided that calling something like:


sendEvent('video1','stop')

will in fact stop the player that's reference-able through the name "video1"

videoguy
03-17-2008, 02:23 PM
ddadmin,

I really appreciate your help on this. I am much closer but the call sendEvent(header.title,'stop') is not working for me. In looking at the code within switchicon.js it's obvious the coding style there differs from that used in the functions I have been provided with the player I am using. Could that be the issue.

If I comment out the sendEvent(header.title,'stop') the script works as before but when I don't then clicking on the open/close icons doesn't work. In fact the first appears closed and the second and third are open and I can see the players and in fact control them.

Anything else you might suggest? Once again Thank You

ddadmin
03-17-2008, 11:44 PM
It seems to me from the above that the problem is with sendEvent("someplayer",'stop'). Have you verified that it works in stopping a player when called on its own (ie: a fresh page without Switch Content script added)? If so, what's the relationship between the string "someplayer" and it being used to identify the player? For example, would "someplayer" be the ID attribute of the player?

videoguy
03-18-2008, 12:08 AM
Yes, the SOMEPLAYER is the javascriptid of the player. I am using 3 .js files to create and display the 3 players. All are identical save the javascriptid's. Here is that code in the hope you may see a conflict that I can correct.

{var so = new SWFObject('jbt.swf','player1','444','353','8');
so.addParam('allowfullscreen','true');
so.addVariable('enablejs','true');
so.addVariable('javascriptid','player1');
so.addVariable('file','my2cents3.mov');
so.addVariable('autostart','false');
so.addVariable('displayheight','333');
so.addVariable('height','353');
so.addVariable('width','444');
so.addVariable('screencolor','0x3366FF');
so.addVariable('frontcolor','0xFFFFFF');
so.addVariable('backcolor','0xOOOOOO');
so.addVariable('showicons','true');
so.addVariable('showcontrols','true');
so.addVariable('transparent','false');
so.addVariable('showdownload','true');
so.addVariable('link','force_download.php?file=my2cents3.mov');
so.addVariable('linktarget','_self');
so.addVariable('fallback','my2cents.flv');
so.addVariable('volume','40');
so.addParam('menu','true');
so.write('player1')};

BTW, on other pages I have on my web site I use the functions and the call and they work as intended. It is only since attempting to use your great script that I've had an issue with this approach.

ddadmin
03-18-2008, 11:35 AM
Do you have URLs to two pages:

1) One with Switch Content and the player script together that doesn't work
2) One with just the player on it and does work (clicking on a link for example stops the player from playing).