Link to home
Start Free TrialLog in
Avatar of adrian7474
adrian7474Flag for United States of America

asked on

Create My Own Universal Flash Player

I would like to know to create a youtube like flash player. I basically want to embed a swf object and then feed different videos to it. Right now, I made a xml driven video player, however, I would have to create a new swf and xml list for each video I want to embed on my site. This is a real drag and pain. What is the procedure to make a universal player like youtube.
FYI: I can't use flow player because it uses java script and I would like the pages I make on my site to be able to share on facebook.
thanks
a
Avatar of CyanBlue
CyanBlue
Flag of United States of America image

Can you explain why you are saying this???
   ---
   I would have to create a new swf and xml list for each video
   ---

CyanBlue
Avatar of adrian7474

ASKER

Ok, so I created a flash file called "myplayer" and in it I have a flv playback component that calls an xml file(mylist) that feeds it the video source(mp4 file) and plays it. If I embed this swf (myplayer.swf) on my web page, all is good. However, now I create another page on my site and want to embed myplayer.swf on it, however, I would like the video to play a different video. If I change the xml file that feeds it, it will also change the original page too. So now I have to duplicate the fla(myplayer2.swf) file, change the actionscript to call different xml(myplayer2) every time I need to add a new page with this custom player i created. Huge pain.
Does this help explain why?
I guess I don't understand this line...
   ---
   If I change the xml file that feeds it, it will also change the original page too.
   ---

What do you really mean by 'different xml'???  Is it just two different XML file with the same structure or are they different in structure as well???
I am thinking you should really lock the structure of the XML and just specify the name of the video in it and it should work fine on displaying different video files with no problem???

CyanBlue
I will try one more time.
Structure:
Player.swf => Player.xml => video,mp4
(ie Player.swf calls Player.xml which has video file path in it. )
Example xml structure:
<item>
<data>mysite.com/video.mp4</data>
</item>

Now, I WANT to use my player for all videos I put on my site and have it be dynamic (LIKE YOUTUBE).
Meaning, if player.swf was on two different pages, but each page has a different video file associated with it, how would i do this with out having to create a new swf, new xml file???

Hm...  That does not tell me why it is changing the original page...  Do you have an example page up that I can take a look???

CyanBlue
No, I haven't posted anything yet, I am in the r & d stage of mysite. Besides, wouldn't the fla file be a better example choice? I feel you are not understanding what I am trying to accomplish. I am just frustrated at this point, I have explained this several times already.
One last time.

If I embed one swf container that uses xml to get the data onto two different html pages and change the xml file data, the player swf will change on both pages. However, I want to use a different video for each page, but use the same swf player, how would I accomplish this?
Okay...  If I have two player.swf embedded in one HTML file...  Both of the player.swf files are the same one which is linked to different XML sources, ie the first player.swf is provided to read youtube.xml and the second player.swf is provided with vimeo.xml file...

To my knowledge, that setup should never affect each other, but you are saying it does...  That's why I said I'd like to see it in action because I can diagnose why it might be happening without going through the complicate script...  

If you feel like we are not communicating well, you are feel free to click on the Request Attention link on top of this page to request to close this topic and open a new one...  I wouldn't be offended if you do that...

CyanBlue
Ok, almost there. How do i have one swf player to be used on several pages all containing different videos. Like youtube has one player that serves millions of different videos.
Just feed the different XML source file per embed...  
Can you post your HTML code you are using???

CyanBlue
Avatar of Antonio Estrada
Let me see if I got this right...

You have Player.swf.

Somewhere in that file you have some line similar to this:

var urlRequest:URLRequest = new URLRequest("PLAYLIST.xml");
var xmlLoader:URLLoader = new URLLoader(urlRequest);
xmlLoader.addEventListener("complete", xmlLoaded);

If so, that first line is the issue. Every time it will try to load from the same "playlist" (same xml), so creating a new playlist means generating a new swf with something like "OTHER_PLAYLIST.xml" as the target, thus the hassle.

It can be avoided if you send that parameters via HTML and catch it on the swf. Kinda like this:

<code>

Also, as you can see, I'm using swfObject (an old version due to several reasons, but hey, it works), you can download that specific version from here: http://blog.deconcept.com/swfobject/

Now, the only thing you'd need to change is the HTML for the swf to load different XML files.

Good luck.

-V
//html
<html>
<head>
<script type="text/javascript" src="./swfobject.js"></script>
<body>
<div id="flashcontent"></div>
  <script type="text/javascript">
    // <![CDATA[
    var so = new SWFObject("Player.swf", "Player", "550", "400", "9", "#FFFFFF");
    so.addParam("wmode", "transparent");
    so.addVariable("targetXML", "SOME_PLAYLIST.XML");
    so.write("flashcontent");
    // ]]>
  </script>
</body>
</html>

//AS
var targetXML:String = root.loaderInfo.parameters.targetXML;
var urlRequest:URLRequest = new URLRequest(targetXML);
var xmlLoader:URLLoader = new URLLoader(urlRequest);
xmlLoader.addEventListener("complete", xmlLoaded);

Open in new window

Sorry for the delay. This sounds about what I would want, only I can't get it going. I looked at a bunch of documents and tutorial online, but can't figure out to get it to work with video fed by xml. I followed this example on adobe: http://www.adobe.com/devnet/flashplayer/articles/alternative_content.html
and tried to get it to work with xml and can't.
I applied your code example and i get this error:
1120: Access of undefined property xmlLoaded.
ASKER CERTIFIED SOLUTION
Avatar of Antonio Estrada
Antonio Estrada
Flag of Mexico image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks so much. This is great. I would like to be able to have this be embeddable. Meaning so i could use a url like this
<embed src="http://www.example.com/player.swf" flashvars="video_id=123456789" width="300" height="200" type="application/x-shockwave-flash" />
Would this be possible? I will ask this in another question too, cause you deserve credit for this (so look out for it and hopefully you can help solve this one:) )
thanks again,
a
Awesome this expert was
Glad to help :)

And yeah, a tag like that seems fine to me, but we can get into detail if you like. (Although, what we're doing with swfObject is embedding it, though we don't get the tag like that, so you can't move it to somewhere else).

-V