Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to have swf video playback stop on site tab click?

Status
Not open for further replies.

Kisaragi

Technical User
Feb 10, 2007
5
CA
Hello..

First off i'm new here and hoping i could get some help..

it has been thrust upon me in my office to learn and update the site web page which was writen by someone else who has knowledge of php and swf. I having know php knowledge am cutting my way through as best as possible. but i have come across this road block i can't seem to cross.

There is and embedded swf video player that plays site videos on a random loop.. I have been requested to have this player stop playing the loop upon a click of any of the tabs on the page..

here is the scripting as i know it so far that is on the page currently.

This loads the video player

<iframe src="./video/video.php" height=285 width=320 frameborder=0 border=0 name="fvp"></iframe>

This is the video player it loads

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "<html>
<head>
<title>videoplayerclassic</title>
<meta http-equiv="Content-Type" content="text/html; charset=shift_jis">
<meta name="author" content="">
<meta name="generator" content="SWiSHmax <meta name="description" content="videoplayerclassic">
<meta name="keywords" content="ashley, ingram, music, player, school, video">
<script src="./mpl.js" type="text/javascript"></script>

</head>
<body bgcolor="#ffffff" topmargin="0" leftmargin="0" bottommargin="0" rightmargin="0">
<left>
<?php
function counter($v_path){
$v_path = str_replace("./vdo/", "./cnt/", $v_path);
$v_path = str_replace(".swf", ".dat", $v_path);
if (file_exists($v_path)) {
$yomiko=file($v_path);
$fp = @fopen($v_path, "r+");
flock($fp, 2);
$yomiko[0]++;
fputs($fp, $yomiko[0]);
flock($fp, 3);
fclose($fp);
} else {
$ret = touch($v_path);
$datap = file($v_path);
$fp = @fopen($v_path, "r+");
flock($fp, 2);
fputs($fp, "1");
flock($fp, 3);
fclose($fp);
};
};


$va = $_REQUEST["va"];
if ($va != ""){
$va = str_replace("video/" , "" , $va);
echo" <script type=\"text/javascript\">
<!--
mpw(\"$va\");
// -->
</script>
";
counter($va);
} else {

$data = file("data.txt");
$newdata = Array();
for($i=0;$i<sizeof($data);$i++){
list($videoa,$pica,$videon,$videod) = explode("<>",$data[$i]);
$newdata[$i] = "$videoa";
};
shuffle($newdata);
$address = $newdata[0];
$address = str_replace("video/" , "" , $address);
echo" <script type=\"text/javascript\">
<!--
mpw(\"$address\");
// -->
</script>
";
};


?>
</left>
</body>
</html>

and within the video player it loads the background swf

function mpw(ura){
document.write('<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\" id=\"videoplayerclassic\" width=\"320\" height=\"284\">\n');
document.write('<param name=\"movie\" value=\"videoplayerclassic.swf\">\n');
document.write('<param name=\"bgcolor\" value=\"#EEEEEE\">\n');
document.write('<param name=\"quality\" value=\"high\">\n');
document.write('<param name=\"allowscriptaccess\" value=\"samedomain\">\n');
document.write('<PARAM NAME=FlashVars VALUE=\"vaddress=' + ura + '\">\n');
document.write('<embed type=\"application/x-shockwave-flash\" pluginspage=\" name=\"videoplayerclassic\" width=\"320\" height=\"284\" src=\"videoplayerclassic.swf\" FlashVars=\"vaddress=' + ura + '\" bgcolor=\"#EEEEEE\" quality=\"high\" swliveconnect=\"true\" allowscriptaccess=\"samedomain\">\n');
document.write('<noembed>\n');
document.write('</noembed>\n');
document.write('</embed>\n');
document.write('</object>\n');
}

within the video player it requests information on the videos from a data.txt as follows

./video/vdo/20061208120543.swf<>./video/pic/20070118114131.jpg<>Manami - Natural Woman<>3?07?<>0
./video/vdo/20061208122433.swf<>./video/pic/20061208122433.jpg<>Rina<>7?31?<>0
./video/vdo/20061208123216.swf<>./video/pic/20061208123216.jpg<>Hanako<>7?26?<>0
./video/vdo/20061208123703.swf<>./video/pic/20061208015334.jpg<>Nobuko - Safe<>3?14?<>0
./video/vdo/20061208124616.swf<>./video/pic/20061208124616.jpg<>Yumi<>8?13?<>0
./video/vdo/20061208125004.swf<>./video/pic/20061208015311.jpg<>Taeko<>3?36?<>0
./video/vdo/20061208125430.swf<>./video/pic/20061208125430.jpg<>Akiko<>4?13?<>0
./video/vdo/20061216075503.swf<>./video/pic/20061221094308.jpg<>Ashley Ingram - You’re The One<>4?56?<>0
./video/vdo/20061221113135.swf<>./video/pic/20061221113135.jpg<>Kaori - Unbreak My Heart<>4?39?<>0
./video/vdo/20070108063112.swf<>./video/pic/20070108063112.jpg<>Tomoko Koizumi - 8 Month Journey<>4?19?<>0

The tabs are defined by

<?php
require("nakami/waku.txt");
?>

which gets it's informations from the waku.txt as follows

<?php
function henkan($url){
$text = file_get_contents($url);
$ttxt = nl2br($text);
$ttxt = str_replace("\r\n", "\r", $ttxt);
$ttxt = str_replace("\r", "\n", $ttxt);
$ttxt = str_replace("\n", "", $ttxt);
$ttxt = str_replace("<br />", "", $ttxt);
echo($ttxt);
};
?>
<script type="text/javascript">
<!--
if (document.images) {
btn0 = new Image();
btn0.src = "nakami/img/0.gif";
btn1 = new Image();
btn1.src = "nakami/img/a1.gif";
btn2 = new Image();
btn2.src = "nakami/img/a2.gif";
btn3 = new Image();
btn3.src = "nakami/img/a3.gif";
btn4 = new Image();
btn4.src = "nakami/img/a4.gif";
}
function setImage(name, src) {
if (document.images) {
document.images['btn0'].src = 'nakami/img/0.gif';
document.images['btn1'].src = 'nakami/img/1.gif';
document.images['btn2'].src = 'nakami/img/2.gif';
document.images['btn3'].src = 'nakami/img/3.gif';
document.images['btn4'].src = 'nakami/img/4.gif';
document.images[name].src = src;
}
}
// -->
</script>
<script language="JavaScript">
<!--
var ns4=document.layers?1:0
var ie=document.all?1:0
var ns6=document.getElementById&&!document.all?1:0
var IsInit = 0
var tabcont=new Array()

tabcont[0]='<?php require("nakami/project.php");?>'
tabcont[1]='<?php henkan("nakami/intro.txt") ?>'
tabcont[2]='<?php henkan("nakami/course.txt") ?>'
tabcont[3]='<?php henkan("nakami/koe.txt") ?>'
tabcont[4]='<?php henkan("nakami/gaiyo.txt") ?>'
var subobj=""
function showit(tabnum) {
currentCont=(tabnum==-1)?"":tabcont[tabnum]
if (ns4) {
subobj=document.contArea1.document.contArea2
subobj.document.write(currentCont)
subobj.document.close()
} else if (ie||ns6) {
subobj=ns6?document.getElementById("contArea3"):document.all.contArea3
subobj.innerHTML=currentCont
}
if (IsInit==0) {
IsInit=1
}
}

//-->
</script>

<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td><a href="" onclick="setImage('btn0', 'nakami/img/a0.gif');showit(0);return false;"><img name="btn0" src="nakami/img/a0.gif" border="0"></a></td>
<td><a href="" onclick="setImage('btn1', 'nakami/img/a1.gif');showit(1);return false;"><img name="btn1" src="nakami/img/1.gif" border="0"></a></td>
<td><a href="" onclick="setImage('btn2', 'nakami/img/a2.gif');showit(2);return false;"><img name="btn2" src="nakami/img/2.gif" border="0"></a></td>
<td><a href="" onclick="setImage('btn3', 'nakami/img/a3.gif');showit(3);return false;"><img name="btn3" src="nakami/img/3.gif" border="0"></a></td>
<td><a href="" onclick="setImage('btn4', 'nakami/img/a4.gif');showit(4);return false;"><img name="btn4" src="nakami/img/4.gif" border="0"></a></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table border="0" cellpadding="0" cellspacing="0" bgcolor="#f7efe7">
<tr height="16"><td></td><td></td><td></td></tr>
<tr>
<td>
<div class="frm" onload="showit(0)">
<!--------------------------------- ?{?¶?\?¦?p???C???[?Ì?T?C?Y?ð?w?è?iNN4?p?j -------------------------->
<ilayer name="contArea1" width="500" height="800">
<layer name="contArea2" width="500" height="800"></layer>
</ilayer>
<div id="contArea3"></div>
</div></td></tr></table>


</td>
</tr>
</table>

I need the player to stop playing video when any one of the tabs (btn0 through btn4) are clicked.

Is this possible? If so I am requesting any help and requesting what chages to the scripting need to be made.

I will thank ahead of time to anyone who can provide me with some insite..

Thanks
 
this is possible.

some different approaches:

1. test in php for the clicks that you DO NOT want the fid to play. then do not populate the iframe src attribute.

or

2. test in php for the clicks that you DO NOT want the vid to play. leave everything as it is but put a javascript onload event into your script that kills the playback. you can find the flash external API at this address


you would need something like this

Code:
<script language="JavaScript">
    // Use a variable to reference the embedded SWF file.
    var flashVideoPlayer;
    
    /* When the HTML page loads (through the onLoad event of the <body> tag), it calls the initialize() function. */
    function initialize() {
      
        var isIE = navigator.appName.indexOf("Microsoft") != -1;
        flashVideoPlayer = (isIE) ? window['videoPlayerClassic'] : document['videoPlayerClassic'];
    }

    function callFlashPlayPauseVideo() {
        flashVideoPlayer.pauseResume();
    }
   function pauseMe() {
   initialize();
   callFlashPlayPauseVideo();
}
</script>

....
<body onLoad="pauseMe(); return true;">

the above is javascript - post comments/question in the js forum by preference.


if the buttons are not live (i.e. they do not point to other locations) then just add the pauseMe()

Code:
<td><a href="" onclick="setImage('btn0', 'nakami/img/a0.gif');showit(0);[red]pauseMe();[/red]return false;"><img name="btn0" src="nakami/img/a0.gif" border="0"></a></td>
 
Thank You jpadie unfortunatly neither of those worked.. both options end up reloading the player on every click.

Thanks though
 
then you have implemented them incorrectly. there is no reason for the page or video to have been reloaded.
 
Hello jpadie or anyone else who can help.

As I mentioned i am new to php and have tried to implement the coding jpadie suggested and it does not work.

put the "pauseMe()" exactly where shown and nothing

and tried to implement the other listed as follows

<?php
function henkan($url){
$text = file_get_contents($url);
$ttxt = nl2br($text);
$ttxt = str_replace("\r\n", "\r", $ttxt);
$ttxt = str_replace("\r", "\n", $ttxt);
$ttxt = str_replace("\n", "", $ttxt);
$ttxt = str_replace("<br />", "", $ttxt);
echo($ttxt);
};
?>
<script type="text/javascript">
<!--
if (document.images) {
btn0 = new Image();
btn0.src = "nakami/img/0n.gif";
btn1 = new Image();
btn1.src = "nakami/img/a1r.gif";
btn2 = new Image();
btn2.src = "nakami/img/a2.gif";
btn3 = new Image();
btn3.src = "nakami/img/a3.gif";
btn4 = new Image();
btn4.src = "nakami/img/a6.gif";
btn5 = new Image();
btn5.src = "nakami/img/a5.gif";
btn6 = new Image()
btn6.src = "nakami/img/a4.gif";
btn0a = new Image();
btn0a.src = "nakami/img/0n.gif";
btn1a = new Image();
btn1a.src = "nakami/img/a1r.gif";
btn2a = new Image();
btn2a.src = "nakami/img/a2.gif";
btn3a = new Image();
btn3a.src = "nakami/img/a3.gif";
btn4a = new Image();
btn4a.src = "nakami/img/a6.gif";
btn5a = new Image();
btn5a.src = "nakami/img/a5.gif";
btn6a = new Image()
btn6a.src = "nakami/img/a4.gif";

}
function setImage(name, src) {
if (document.images) {
document.images['btn0'].src = 'nakami/img/0n.gif';
document.images['btn1'].src = 'nakami/img/1r.gif';
document.images['btn2'].src = 'nakami/img/2.gif';
document.images['btn3'].src = 'nakami/img/3.gif';
document.images['btn4'].src = 'nakami/img/6.gif';
document.images['btn5'].src = 'nakami/img/5.gif';
document.images['btn6'].src = 'nakami/img/4.gif';
document.images['btn0a'].src = 'nakami/img/0n.gif';
document.images['btn1a'].src = 'nakami/img/1r.gif';
document.images['btn2a'].src = 'nakami/img/2.gif';
document.images['btn3a'].src = 'nakami/img/3.gif';
document.images['btn4a'].src = 'nakami/img/6.gif';
document.images['btn5a'].src = 'nakami/img/5.gif';
document.images['btn6a'].src = 'nakami/img/4.gif';
document.images[name].src = src;
}
}
// -->
</script>
<script language="JavaScript">
<!--
var ns4=document.layers?1:0
var ie=document.all?1:0
var ns6=document.getElementById&&!document.all?1:0
var IsInit = 0
var tabcont=new Array()

tabcont[0]='<?php henkan("nakami/intro.txt")?>'
tabcont[1]='<?php require("nakami/project.php");?>'
tabcont[2]='<?php henkan("nakami/course.txt") ?>'
tabcont[3]='<?php henkan("nakami/koe.txt") ?>'
tabcont[4]='<?php henkan("nakami/news.txt") ?>'
tabcont[5]='<?php henkan("nakami/lang.txt") ?>'
tabcont[6]='<?php henkan("nakami/gaiyo.txt") ?>'
var subobj=""
function showit(tabnum) {
currentCont=(tabnum==-1)?"":tabcont[tabnum]
if (ns4) {
subobj=document.contArea1.document.contArea2
subobj.document.write(currentCont)
subobj.document.close()
} else if (ie||ns6) {
subobj=ns6?document.getElementById("contArea3"):document.all.contArea3
subobj.innerHTML=currentCont
}
if (IsInit==0) {
IsInit=1
}
}

//-->
</script>

<script language="JavaScript">
// Use a variable to reference the embedded SWF file.
var flashVideoPlayer;

/* When the HTML page loads (through the onLoad event of the <body> tag), it calls the initialize() function. */
function initialize() {

var isIE = navigator.appName.indexOf("Microsoft") != -1;
flashVideoPlayer = (isIE) ? window['videoPlayerClassic'] : document['videoPlayerClassic'];
}

function callFlashPlayPauseVideo() {
flashVideoPlayer.pauseResume();
}
function pauseMe() {
initialize();
callFlashPlayPauseVideo();
}
</script>

<table width="700" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td><a href="" onclick="setImage('btn0', 'nakami/img/a0n.gif');showit(0);return false;"><img name="btn0" src="nakami/img/a0n.gif" border="0"></a></td>
<td><a href="" onclick="setImage('btn1', 'nakami/img/a1r.gif');showit(1);return false;"><img name="btn1" src="nakami/img/1r.gif" border="0"></a></td>
<td><a href="" onclick="setImage('btn2', 'nakami/img/a2.gif');showit(2);return false;"><img name="btn2" src="nakami/img/2.gif" border="0"></a></td>
<td><a href="" onclick="setImage('btn3', 'nakami/img/a3.gif');showit(3);return false;"><img name="btn3" src="nakami/img/3.gif" border="0"></a></td>
<td><a href="" onclick="setImage('btn4', 'nakami/img/a6.gif');showit(4);return false;"><img name="btn4" src="nakami/img/6.gif" border="0"></a></td>
<td><a href="" onclick="setImage('btn5', 'nakami/img/a5.gif');showit(5);return false;"><img name="btn5" src="nakami/img/5.gif" border="0"></a></td>
<td><a href="" onclick="setImage('btn6', 'nakami/img/a4.gif');showit(6);return false;"><img name="btn6" src="nakami/img/4.gif" border="0"></a></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table width="700" border="0" cellpadding="0" cellspacing="0" bgcolor="#f7efe7">
<tr height="16"></tr>
<tr>
<td>
<div class="frm" onload="showit(0)">
<!--------------------------------- ?{?¶?\?¦?p???C???[?Ì?T?C?Y?ð?w?è?iNN4?p?j -------------------------->
<ilayer name="contArea1" width="700" height="800">
<layer name="contArea2" width="700" height="800"></layer>
</ilayer>
<div id="contArea3"></div>
</div></td></tr></table>


</td>
</tr>
</table>

<table width="700" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><table border="0" cellpadding="0" cellspacing="0">
<tr>
<td><a href="" onclick="setImage('btn0a', 'nakami/img/a0n.gif');showit(0);return false;"><img name="btn0a" src="nakami/img/a0n.gif" border="0"></a></td>
<td><a href="" onclick="setImage('btn1a', 'nakami/img/a1r.gif');showit(1);return false;"><img name="btn1a" src="nakami/img/1r.gif" border="0"></a></td>
<td><a href="" onclick="setImage('btn2a', 'nakami/img/a2.gif');showit(2);return false;"><img name="btn2a" src="nakami/img/2.gif" border="0"></a></td>
<td><a href="" onclick="setImage('btn3a', 'nakami/img/a3.gif');showit(3);return false;"><img name="btn3a" src="nakami/img/3.gif" border="0"></a></td>
<td><a href="" onclick="setImage('btn4a', 'nakami/img/a6.gif');showit(4);return false;"><img name="btn4a" src="nakami/img/6.gif" border="0"></a></td>
<td><a href="" onclick="setImage('btn5a', 'nakami/img/a5.gif');showit(5);return false;"><img name="btn5a" src="nakami/img/5.gif" border="0"></a></td>
<td><a href="" onclick="setImage('btn6a', 'nakami/img/a4.gif');showit(6);return false;"><img name="btn6a" src="nakami/img/4.gif" border="0"></a></td>
</tr>
</table></td>
</tr>
</table>

<body onLoad="pauseMe(); return true;">

what is it i am doing wrong

Any help is appreciated

thanks
 
Don't know if this will help

the structure of the page is as follows

index php page
loads a left panel page through txt video play in this section
loads a center panel trhough txt with the tabs

7 tabs load pages within the center panel from txt files

would like the video in the left panel to stop
when any tab is clicked in the center panel


Also side issue center panel has 7 tabs across the top
and the 7 tabs duplicated across the bottom
defined as indepenant btns for all 14
would like both top 7 & the bottom 7 btns to mirror
basically when btn0 clicked btn0a also changes to match
when btn1 clicked btn1a also changes to match
and so on to btn6
and vice versa
when btn0a clicked btn0 also changes to match
when btn1a clicked btn1 also changes to match
and so on to btn6a

thank you
 
you are asking javascript/flash questions. this really is not the right forum.

as a last gasp try changing the buttons to the following:

Code:
   <td><a href="" onclick="setImage('btn0a', 'nakami/img/a0n.gif');showit(0);pauseMe();return false;"><img name="btn0a" src="nakami/img/a0n.gif" border="0"></a></td>
//etc

and when you postback in the javascript forum, be sure to tell them what error messages you are getting. you can view the errors in most browsers but there is no standard way of doing so. I assume you have read in detail the link that I provided and followed their recommendations for implementing a pause/play function. If not, I STRONGLY recommend that you do so before posting again.
 
Thank You jpadie for being patient with me..

I did not know this was a javascript post thought because it loaded from the intial index php that it belonged here.

I have tried the pauseMe() as you suggested with failed results..

I will gladly post in the javascript forum..

is there a way of relocating this entire thread...

Thanks
 
you can ask the moderators to relocate the thread. typically they do not, however.

to contact the mods use the red flag mechanism.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top