Page 1 of 1

Two problems with using php to play video player

Posted: Sat May 22, 2010 2:15 pm
by jtmuser
I'm a bit new at this, but I'm making progress, just to let you know how basic your answer needs to be.

I was all excited about creating a horse sales page until I noticed two problems. I was wondering if anyone had any suggestions about how better to do this.

I have a list of four sample horse names on the page right now. If you click on a horse, php loads a photo and description of that horse from a database based on its associated ID.

It also gets an associated video name and filename and changes the video title and filename in an xml file, which loads the appropriate video into the flash player on the page.

It all looked great and I was on top of the world for about five minutes.

The two problems are this:

In Explorer (my favorite browser), the browser caches the first video loaded on the page, and then if you click on the other horse names, the video player continues to keep loading the first video and won't play the newly selected video, even though the source code in the xml page is changing correctly. If you clear the browsing history, then you can click on another horse and get the appropriate video, but then that video sticks and no matter what horse you pick you still see that video, etc.

I've tried using cache-clearing code that I found elsewhere and that's not working, but before I pursue why that's not working, here's a bigger problem.

If two people click on different horse titles at the same time, the xml file just goes with one of the selections and both users see whichever selection that is. So, someone might be trying to look at horse A but see horse B's video, because someone somewhere else clicked on that one at the same time.

So, my question is, can anyone think of a better way to do this?

I think it's safe to say that using php to change an xml file will not work in this scenario given that, if many users actually try to use it, I'm in trouble.

So, I need to get the video selection onto this page some other way.

Thanks in advance,

Joanie

Re: Two problems with using php to play video player

Posted: Mon May 24, 2010 8:31 am
by markusn00b
For your first issue, see this link.

For your second issue, you've encountered what we call a race-condition, of sorts. Now, I don't know how you're serving the flash player, but if it requires an XML file to load it's data, then it's a shoddily-written application, for reasons you have discovered. What Flash player are you using? There are many decent ones out-there, such as JW FLV Player, that allow to send Flash vars to the Flash player, so it can load the correct video.

Anyway, take a look and post back with any questions :)

Re: Two problems with using php to play video player

Posted: Mon May 24, 2010 2:21 pm
by jtmuser
Thank you for tackling my problem.

I put the caching code, if that's the proper term, in the file, and at first it didn't look like it was working, but I figured out that it is indeed working. There's some sort of time delay in IE that's not changing the xml file fast enough to load the correct video when I click on the headline. It loads it correctly after a while.

But, we've already concluded this xml setup is not the way to go.

I'm afraid I don't know very much. I'm a career journalist working to build my programming skills. This is all I do in every spare moment, but it's so hard to know when you're learning something good or bad. I learned the xml approach from Lynda.com, and it does work if you have a set list of videos that you are playing in a video player. It's not going to work for a changing playlist.

I need to follow your suggestion and learn how to use variables to load the video. I'll have to look for that tutorial somewhere. Feel free to direct me.

Meanwhile, let me ask you one question: Am I going down the wrong path using the Flash video player? Would it be better if I tried to load the video through javascript and embed it in the page with an embed code? I don't know javascript, other than a few things I've picked up. I have a new book sitting here next to me. I just don't know what to focus on. I don't want to waste time.

You've been most helpful. Thanks so much.

Joanie

Re: Two problems with using php to play video player

Posted: Mon May 24, 2010 5:06 pm
by Reviresco
Are you trying to load the new video without reloading the page, or is it okay to reload the page when a new video is selected?

Re: Two problems with using php to play video player

Posted: Tue May 25, 2010 12:28 pm
by jtmuser
Reloading the page is fine.

Re: Two problems with using php to play video player

Posted: Wed May 26, 2010 11:27 am
by Reviresco
Okay I tried pasting some code from my embedded Flash players but the lines are too long and I couldn't get them to wrap, so I'll try explaining it instead.

I do this all the time by using the "get" variables -- for example, http://www.example.com?video=112. Using php I grab the video number or name, such as $_GET['video'], look up the name of the video (I'm using a MySQL database), and then echo it into the embedded Flash player's parameters, for example in this snippet:

Code: Select all

&stream_name=<?php echo $video_name;?>
Then for your links, just include that get variable, http://www.example.com?video=112 and the video will load. Also be sure to set a default video to load for the first time they end up on that page.

The reason I use "get" as opposed to "post" is so users can bookmark the video.

For examples of this, here's one of my websites: http://www.healthcornertv.com

Re: Two problems with using php to play video player

Posted: Wed May 26, 2010 12:42 pm
by jtmuser
If you're tired of me, you can stop answering. I really appreciate all the time you've put into this already.

I actually understand everything you said about pulling the video name out of an SQL database and using "get" variables to pass the data to the video player.

It's the actionscript that I'm just staring at.

The video player actionscript code I used (as taught to me on the tutorial I mentioned previously) looks like the following:

var xml:XML = new XML();
xml.ignoreWhite = true;

xml.onLoad = function() {
var nodes = this.firstChild.childNodes;
for(i=0;i<nodes.length;i++) {

list.addItem(nodes.attributes.desc, nodes.attributes.flv);
}

vid.load(list.getItemAt(0).data);

}
xml.load("videossales.xml");

var lList:Object = new Object();
lList.change = function() {
vid.contentPath = list.getItemAt(list.selectedIndex).data;
vid.play();
}
list.addEventListener("change",lList);

--------

I barely understand what I'm looking at.

You're saying I should use this: &stream_name=<?php echo $video_name;?> (can't get the ampersand symbol to look like an ampersand in this thing)

I don't know what to do with this code in my actionscript. Does this code just replace my xml.load("videossales.xml")? Or do I need to rewrite all the code? In which case I'm in trouble.

I clearly have a lot to learn in Flash.

But I really appreciate you showing me what direction I should be heading. I understand get variables, PHP and SQL databases. I'm pretty excited that I'm up to speed there.

Thanks so much.

Joanie

Re: Two problems with using php to play video player

Posted: Wed May 26, 2010 4:53 pm
by Reviresco
Not real proficient at actionscript I'm afraid. The snippet I used was for the actual xhtml to embed a Flash player in the page.

What are you using to embed the player? Do you have a link for the page where it resides?

Re: Two problems with using php to play video player

Posted: Fri May 28, 2010 1:11 pm
by jtmuser
Sorry it took me so long to get back. Yesterday's free time got eaten up renewing car and drivers licenses, and that was my second attempt to do it. The joys ...

To answer your question of how I embed the video, sadly, I let Dreamweaver embed it, and I'm not really sure what the code is.

It looks like this:

<div id="video_layer">
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shoc ... n=7,0,19,0" width="430" height="360">
<param name="movie" value="../playlistsales.swf" />
<param name="quality" value="high" />
<embed src="../playlistsales.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="430" height="360"></embed>
</object>
</div>

You can view the page at whinny.biz/details_sales.php. The video part (videos changing when each link is clicked on) works properly on Safari and that's about it.

You're saying that the code I should be changing is that embed code?

I didn't mention in my previous post that the site you sent me to was really impressive. Obviously, you've mastered embedded video.

Thanks for the help.

Joanie

Re: Two problems with using php to play video player

Posted: Tue Jun 01, 2010 4:52 pm
by Reviresco
First part:

Code: Select all

$article_id = $_GET['article_id'];

switch($article_id) {
	case 3:
	$video = 'turnout1.flv';
	break;
	case 4:
	$video = 'dressage1.flv';
	break;
	case 5:
	$video = 'running1.flv';
	break;
	case 6:
	$video = 'jumping1.flv';
	break;
	default:
	$video = 'turnout1.flv';
	}
Second part -- video embed -- something similar to this:

Code: Select all

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="430" height="360">
    <param name="FlashVars" value="&skinName=Your_Skin_Name_Here&streamName=videos_sales/<?php echo $video;?>&autoPlay=true&autoRewind=true" />
    <param name="quality" value="high" />
    <param name="movie" value="../playlistsales.swf" />
    <embed src="../playlistsales.swf" quality="high" flashvars="&skinName=Your_Skin_Name_Here&streamName=videos_sales/<?php echo $video;?>&autoPlay=true&autoRewind=true" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="430" height="360"></embed>
  </object>
I'm guessing you'll need to remove that action script/xml playlist thing, but I'm not sure.

Also there are a bunch of errors on the page: a lot of unclosed <li> tags, and be sure to get rid of that <head> with <meta> tags at the bottom of the page. In Dreamweaver, just do a "validate document".

Re: Two problems with using php to play video player

Posted: Wed Jun 02, 2010 4:50 pm
by jtmuser
I understood the switch statement and put that in, along with your video embed code.

I also tried to clean up my tags.

And, I removed the xml line in the actionscript on the video component.

So far, I'm not getting it to work.

I probably need to do more with the actionscript. Perhaps remove more.

But, I get what you're telling me.

Thank you so much for investing so much time on this.

Joanie