How to Load External Flash Video (FLV) Files (AS2)
Note: This article has a companion piece, “How to Control Video (FLV) without a Component.” An ActionScript 3.0 version of this article is located in a more recent entry of this blog.
It has been possible to load external video into a movie since Flash MX (aka Flash 6). Loading FLV files, however, isn’t nearly as intuitive as loading other external media, such as SWFs, JPGs, MP3s, and the like. The MovieClip.loadMovie() method, for example, loads an external SWF with a single line of code. Not so for FLV. So how is it done?
Many people take the route of one of the Flash MX/Flash MX 2004 Media Components or the Flash 8 FLVPlayback Component. These provide the convenience of drag-and-drop setup (just set the contentPath property in your Component Inspector panel) and UI controls for playing, pausing, adjusting volume, and more. Certainly, nice features — but you may simply want a no-frills display, “Just give me the video.” Besides, these Components only ship with the Professional editions of Flash and they do add to the SWF footprint. The older Components weigh between 55KB and 68KB on their own. The newer Component weighs less, but requires a Flash Player 8 SWF and still adds 33KB to your movie.
An answer, short and sweet
Let’s get to business, then. Here’s a virtually 0KB way to add video to your SWFs, compatible back to Flash Player 6*.
- Click on the Options menu of your Library panel (the square-ish icon in the upper right corner) and choose New Video….
- Drag an instance of your new video object to the Stage. Set its height and width as desired.
- While the instance is selected, use the Property inspector to provide an instance name. In this example, we’ll use
videoPlayer. - Add the following ActionScript to a keyframe of the timeline that holds the video object. If you like to be organized (and you do!), create a dedicated scripts layer, but any layer will suffice.
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
videoPlayer.attachVideo(ns);
ns.play("externalVideo.flv");
* Important Note: According to the ActionScript Language Reference, the NetConnection and NetStream classes require Flash Player 7 or higher. In my own experience, I find success publishing to a Flash Player 6 SWF with ActionScript 2.0.
How it works
NetConnection is designed to provide playback of streaming FLVs from a local drive or HTTP address. By supplying the NetConnection.connect() method with a null parameter, we avoid dependence on Flash Media Server (formerly known as Flash Communication Server) in order to play video.
NetStream handles the video stream for NetConnection, and our videoPlayer instance cooperates with all of the above via the Video.attachVideo() method. Finally, our NetStream instance loads the external FLV via the NetStream.play() method.
The desired video will begin playing before the file completely loads — when enough data have buffered — so this is a great way to load sizeable video content without significant download time.
April 14th, 2006 at 11:36 pm
Why doesn’t the Video class have an attachAudio() and an adjustVolume method? I find it somewhat strange on how to adjust the volume of a FLV. Attaching the video using attachVideo() logically makes sense;
VideoInstanceName.attachVideo(ns);
Now attaching the audio to the FLV using the MovieClip’s attachAudio() is strange! I think it would make more sense if the Video class has an attachAudio() that we can use. But we are still not there yet to adjust the volume! We must now add a Sound object by doing the following;
//controlling sound
this.createEmptyMovieClip(”flv_mc”, this.getNextHighestDepth());
flv_mc.attachAudio(stream_ns);
var audio_sound:Sound = new Sound(flv_mc);
audio_sound.setVolume(80);
Weird? Or is it just me?
April 15th, 2006 at 11:22 am
myIP,
Heh, well, I can’t answer your “why” question, of course.
I would love to know more about the in-house evolution of ActionScript. I imagine Colin Moock’s next book — whether it’s ActionScript 3.0: The Definitive Guide, Essential ActionScript 3.0, or whatever (all just conjecture on my part) — will illuminate some of that.
My only guess is that the current API is an outgrowth of historical precedent. The
MovieClipclass existed before theVideoclass did. Sound has always been a part of Flash, and for reasons unknown to outsiders, theMovieClipclass andSoundclass were designed to be used in collaboration. Perhaps it would have been redundant, speaking from an under-the-hood point of view, to include audio members in theVideoclass.Some folks have a difficult enough time (at first) “getting” the relationship among
NetConnection,NetStream, andVideo: it already seems like jumping through hoops, right? But once it makes sense, it makes sense. In any case — not to wax too existential — it is what it is. Even if video isn’t as intuitive a pursuit in Flash as others are, I’m glad to have both video and audio in the API!And, as always, it’s easy enough write a wrapper class to tie these loose ends together.
April 15th, 2006 at 10:52 pm
David — thanks for this great tip. I’ve spent the great part of the whole day attempting to work something similar, and here you’ve done it!
Bravo, really. Quick question: is there a way to add some sort of listener in AS to see when the FLV is finished and send the playhead on to the next frame? Some kind of if/else statement?
Thanks again for your blog!
–Mark
April 16th, 2006 at 4:13 pm
Mark,
Great question! When I originally wrote this article, my intention was to follow up with a “part two” to cover what you’ve asked. I need to do a bit more research before I write a proper sequel, but I’ll tell you what I’ve toyed with so far.
The
Videoclass itself contains no events. (An event is a notification raised by an object when a certain incident occurs. An example of this is theButton.onReleaseevent, which fires after someone clicks a button then releases the mouse.) TheVideoclass features plenty of useful properties and two methods — of which we’ve seenVideo.attachVideo()— but no events. So that’s a dry well.NetConnectionis out, too: only one method, nothing more. ButNetStreamprovides what might be a promising event,NetStream.onStatus. More on that in a moment.Truth be told, I was hoping for, say, a
NetStream.onCompleteevent, but something about video streams apparently makes the notion either too difficult or impossible. (Perhaps video streams simply cannot carry with them data on the expected duration of their content?)The next step, then, is to repeatedly compare the current position of the video against its length. But this isn’t a simple solution, either. Case in point: the
Mediaclass, which also plays video, states the following in its entry for theMedia.totalTimeproperty …The
Mediaclass happens to be the basis for the weighty Media Components discussed above, so I’d like to avoid its use in pursuit of as small a footprint as possible. That said, theMediaclass does provide aMedia.completeevent. I’m guessing it’s founded on the developer-suppliedMedia.totalTimeproperty.Since the
NetStreamclass provides aNetStream.timeproperty, we do have a way to determine what the current position of the video is. If we use some repeating event, such asMovieClip.onEnterframe, or the above-mentionedNetStream.onStatusevent, we could compareVideo.timeto a developer-supplied total. When the former is equal to or greater than the latter, the video has come to its end.I don’t much care for the apparent necessity of a developer-supplied total, because there may be cases where the video’s length is unknown beforehand — and then what? But it’s a start. In the sample below, the number 25 refers to 25 seconds and is completely arbitrary.
Looking through the
NetStream.onStatusevent, I found that it does describe the video buffer (see theNetStream.Buffer.Flushcode property). The case in which “Data has finished streaming, and the remaining buffer will be emptied” (ActionScript 2.0 Language Reference) may signal the end of a stream. Of course, it may also indicate network traffic, and that’s what I’d like to determine before publishing something “official” like a sequel. As soon as I figure it out, though, you’ll see an entry on it.April 17th, 2006 at 3:31 pm
“Perhaps it would have been redundant, speaking from an under-the-hood point of view, to include audio members in the Video class.”- Stiller
I was also thinking the same. Yes, perhaps Moock will illuminate the subject in his next book. Thanks again David.
April 28th, 2006 at 4:21 pm
yay ive been needing this actionscript. thanx :p
May 9th, 2006 at 4:21 pm
Hi David,
That was elegant. Only problem I can’t get video - only audio to show up. Working with Flash MX 2004 on a Mac. Any suggestions?
thanks in advance
andrew
May 11th, 2006 at 7:28 pm
Andrew,
I was successful with this approach in both Flash MX 2004 and 8. Granted, I only have Flash for PC. Are you publishing for Flash Player 6 or higher?
May 31st, 2006 at 2:40 pm
I’ve been working with Captionate to include closed captioning with my Flash Videos. This has required me to load an external FLV using AS. All this works fine, the captions appear and they are synched with the video but I’m having trouble incorporating a Video Controller. Since my videos load after viewer presses “launch video” and then play automatically, I’d like the video to loop back to the beginning and then stop at the opening scene as it would using the FLV Playback Component. Can you show example of Actionscript that will meet my requirements of having a Playback Control with an external video, or direct me to information that can help. I have about 50 videos to caption, so I’d appreciate any help you can give. If you email me directly I can provide my source files. Thanks!!!!! - Diane
June 1st, 2006 at 10:11 am
Diane,
The FLVPlayback Component is even easier to use than the approach described in the above article. If you don’t mind the overhead of this Component — which, at 33KB, isn’t as bad as the older Components (some would argue isn’t bad at all) — and if you don’t mind publishing for Flash Player 8 or higher, just drag an instance of the FLVPlayback Component to the Stage, select the Parameters tab in the Property inspector, and set the contentPath parameter to a path reference to your FLV.
You can handle this via ActionScript by giving your Component instance an instance name, then using that to invoke the contentPath property of the object.
June 23rd, 2006 at 4:44 pm
Hello,
I was wondering how to get FLVPlayback component working with NetConnection and NetStream?
June 23rd, 2006 at 11:24 pm
Andy,
Actually, FLVPlayback takes care of all that for you. See my reply to Diane, above … all you need to do is set the contentPath parameter of that Component. Unless maybe I misunderstood your question?
June 26th, 2006 at 9:00 am
Hello David,
Thanks for your reply. I’m sorry I should have added some detail:
What isn’t clear to me in the F8 language reference regarding NetConnect, NetStream and the FLVPlayBack component is whether setting contentPath for FLVPlayBack is enough to ensure that my .flv video is being streamed to the the component. Or is there some undocumented Actionscript to connect a NetConnect and NetStream instance to FLVPlayBack? Is streaming even possible in the scenario or is it simply progressive download unless the URL I provide in contentPath is from a streaming URL via Flash Media Server?
Thanks again,
June 28th, 2006 at 11:36 am
Hey, Andy,
Yeah, FLVPlayback handles the simulated streaming. That’s one of the benefits of using Components: they’re designed to do the heavy lifting for you. In your case, just set the
contentPathparameter, either via the Property inspector or ActionScript. While this will only give you progressive download — unless you’re using Flash Media Server — it really does feel like streaming to the end user.Keep in mind, of course, FLVPlayback requires that you publish for Flash Player 8 or higher. And it’s only available in the Pro version of Flash, while the approach discussed above can be done in Flash Basic.
June 29th, 2006 at 6:55 am
David,
We have Flash Pro 8 and we are running a .FLV movie. Using the FLVPlayBack we set the contentPath to filename.flv. Also, reading the above post with Andy and Diane we removed the AS code that you described in this article. But the problem we have is viewers are complaining that our video is “choppy” - meaning it starts and stops. As a side note - We are hosting this on a shared server. What are we doing wrong?
Thanks
June 29th, 2006 at 8:27 am
Gary,
There are several factors that determine the smoothness of a video’s playback, including overall size (its dimensions), bitrate and sample rate (of both the video and audio streams), number of channels (mono or stereo), compression, number of keyframes — even the visual characteristics of the content itself (lots of motion versus very little). Add network traffic to the mix, and there you have it … converting video for web use is as complex a discipline as anything else.
You may not be doing anything wrong. You should consider the above facets, though, and experiment with reducing the dimensions, reducing the bitrate, etc., until you produce something as small as reasonably possible, without an unacceptable loss in visual quality. It’s the same balance you must strike with, say, JPGs — but a greater number of properties to fiddle with.
July 1st, 2006 at 9:52 am
I am trying to make a button, and use it to load an external .flv into the FLVPlayback - Player 8 component.
I am not all that professional with flash yet.
Would love to be able to load it from xml file.
If you have an idea, or the knowledge, please post, and please include an example .fla and .xml if possible in zip or rar format as it may save tons of conversation as I have already stated, I am no Flash guru. The reason I need to learn this is I find I have a need to be able to create a .flv player that the clients can pick from many .flv movies to play the one desired. JustKaz
July 1st, 2006 at 7:37 pm
JustKaz,
I’ve got to chuckle. This article is geared away from the FLVPlayback Component, but all the recent comments are geared toward it. Maybe I should write an entry about FLVPlayBack.
What you’re after is certainly doable, but it really merits a tutorial to itself. I see at least four sub-goals, here: a) loading XML into Flash; b) using the loaded XML’s data in ActionScript; c) loading an external FLV into the FLVPlaybackComponent, which has been covered in other comments here; and d) doing the above at the behest of a button, which is probably the easiest part.
I’ve been asked to write an article or two on XML in Flash, and the topic is definitely on my list. In the mean time, here’s a good start.
http://www.kirupa.com/web/xml/index.htm
Remember, big things are made up of lots of little things. Don’t try to swallow the elephant all at once.
Of course, one extremely simple solution — thinking outside the box, here — is to choose a particular name for the external FLV and hard code that … then tell your clients to rename their FLVs, in turn, to that name.
July 5th, 2006 at 2:49 pm
Hi David,
Thank you for your reply. I understand that the article was geared away from FLVPlayback but it seems so silly that there is not simple AS to connect FLVPlayback to a “real” stream, not progressive download.
Is there a way to connect MEdiaDisplay or FLVplayback to a stream using NetConnect and NetStream?
Thanks again,
Andy
July 6th, 2006 at 2:02 pm
Andy,
I may not have been clear on this — apologies, if not
— but to be explicit, true streaming cannot occur without Flash Media Server (or some other media streaming server software, if such a 3rd party solution exists for Flash). Once the server software is installed and configured, the ActionScript hookup is as easy as it was before: simply point it at the stream, rather than a file.
July 21st, 2006 at 9:41 am
David, I’ve spent a whole day try to figure it out and you made it seem so simple! Thanks.
My question is, how can i get flash to loop my flv video?
I’m using Flash 8
Thanks,
Brandon
July 21st, 2006 at 9:32 pm
Brandon,
Check out my reply to Mark’s comment (April 16, 2006). Using either the
MovieClip.onEnterFrameorNetStream.onStatusapproach, you could call theNetStream.play()method again when the video finishes. Does that make sense?This FLV entry is one of my most popular articles, so I should probably write a follow up or two. Write back if this doesn’t answer your question.
July 25th, 2006 at 1:25 am
Hi David,
thanks for the info that u have shared . I have a doubt regarding the progressive streaming could you give a snippet explaining the progressive streaming.
July 25th, 2006 at 10:15 am
maharaja,
I’m afraid I don’t understand your question. There are two concepts in discussion so far: streaming and progressive download. Streaming requires server software; progressive download does not. What sort of snippet are you looking for?
July 26th, 2006 at 12:42 am
i want example in which it uses progressive streaming
i tried the following code:
//**** the code is in Flash 8
nc = new NetConnection();
nc.connect(null);
ns = new NetStream();
my_video.attachVideo(ns);
ns.bufferTime(0);
ns.play(”test.flv”);
//****
but according to my understanding the slider should not be accessible till video is completely loaded but in this case i can play with slider as soon i play the swf… may be i think that size of file is small so that it might be loading quickly . size of test.flv is approx 7 MB would u please put some light thanks in advance
July 26th, 2006 at 9:10 am
maharaja,
This article addresses the display of video without the use of Components — with a Video object only (and some ActionScript) — so I’m not sure what you mean by “slider”. Are you talking about one of the Media Components, or FLVPlayback?
July 27th, 2006 at 9:22 am
David,
thanks for making this information so readily available…it’s brought me much closer to understanding how to achieve what I’m trying to do…I’ve still got one more question though…
So I’m stumped on where I should locate my .flv file in relation to the final .swf that targets it. Does it matter? should I include the full path in my “ns.play(”externalVideo.flv”);” line? Do I have to upload my videos to the web first to test it out, etc etc etc.
thanks for your time!
July 27th, 2006 at 4:22 pm
Hi David,
Thanks for the article… it solved about 1/2 of my problem. I have about 30 flash videos, but want to make a single swf player, and just send the particular video filename to play directly to the swf player. No problem there, it’s working with your script. But, now I don’t have a way to control that video. I’m using Flash MX 2004 on a mac, so I can only publish to flashplayer7.
I know this isn’t the point of your article here, but I was hoping you could help. I’ve tried dragging the MediaPlayback component over and hooking it up to the video, but it doesn’t work. Any suggestions?
Thanks!
Dan
July 28th, 2006 at 3:20 pm
Thanks for your help….I’m not quite sure i understood what you meant (sorry, i’m new to flash and am not familiar with ActionScripting).
I entered the code to monitor the movie and then replaced the ‘trace’ with the NetStream.play() method you mentioned. It didn’t work…but that may not have been what you meant. Here is what my code looks like right now.
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
videoPlayer.attachVideo(ns);
ns.play(”772-2_l.flv”);
this.onEnterFrame = function() {
if (videoPlayer.time >= 20) {
ns.play(”772-2_l.flv”);
delete this.onEnterFrame;
}
}
July 28th, 2006 at 4:40 pm
Three replies to the previous three questions.
Eric,
The location of the FLV, SWF, and HTML document are all significant, especially if you’re using relative paths, as demonstrated above. If you’re using absolute paths, then yes, you’ll have to upload your FLVs to the server in order to test — because that’s there the absolute path points. There is a way around that, so take a look at (Perhaps) Unexpected Point of View: SWF Defers to HTML for a more detailed explanation.
Dan,
For that, if I understand you correctly, you’ll have to set up your path, as referenced in the line as a variable, then feed that variable to your SWF from the outside. There are two basic ways to handle this passing-in of variables: 1) append a query string to the SWF reference in your object param and embed elements, and 2) use FlashVars. From a practical standpoint, both approaches amount to the same thing.
Again, if I understand you, you want a single SWF to be able to load 30 different FLVs, and you want to be able to externally instruct the SWF which FLV to load. Did I hear you right?
Brandon,
You did fine — this was my mistake (thanks for catching it!). It’s not the
Videoclass that provides a time property, but rather, theNetStreamclass. I amended my reply to Mark with correct ActionScript. In your code, the only thing that needs to change is the reference tovideoPlayer.time: change that tons.time. Make sense?July 31st, 2006 at 12:39 am
hi David,
Iam using Flash 8 proffessional version.and not god in actionscript.. just began in it..iam doing a website now..In the website i have used a Mediaplayback component to play a flv..(not a flvplayback component).
flv file is loading from a folder..I uploaded the website..but the flv file playing by step by step..i meant loading little bit then playing..loading then playing..
i want to load it fully first then have to play smoothly.. iam also want to show a loading message in the time of loading..just like “loading…”
i tried a code ——-
onClipEvent(enterFrame){
_root.mymedia.autoPlay = false;
}
—–then it loading first but does’nt play automatically..i need to press play button
this webpage for a portfolio for a company..First impression is the best impression right?:) ..When a customer is opening this page they will not see a jerking video..If iam showing a “loading…” message, they will wait to see and it will play smoothly..
what is the soluiotn David?
Thanks
July 31st, 2006 at 2:32 pm
lijo,
Preloading a video is not unlike preloading a SWF or JPG. Because you’re using one of the Media Components, your first stop should be the
Mediaclass entry in the Components Language Reference. Note theMedia.bytesLoadedandMedia.bytesTotalproperties under the Properties summary. Those properties will give you comparable information to theMovieClip.getBytesLoaded()andMovieClip.getBytesTotal()methods described in How to Tell When an External SWF has Fully Loaded.August 27th, 2006 at 10:48 am
Hello, I just get the audio, no video.
What can I be doing wrong?
This is what I got:
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
FLVPlayback.attachVideo(ns);
ns.play(”2.flv”);
I’m using a PC with Flash Professional 8.0.
August 27th, 2006 at 2:36 pm
Btw, everything works when I put a value for contentPath in the “Component Inspector” but I need to be able to change the content dynamicly. I’m going to have one player that can open different files depending on what data it receives (ex: www.mysite.com/player.swf?id=123). But I can’t get it to work when we have to set the contentPath value in a actionscript.
August 27th, 2006 at 4:14 pm
Markus,
I’m confused by your example code. The
attachVideo()method is defined by theVideoclass, but you seem to be invoking it as a static method of theFLVPlaybackclass. According to the documentation, the FLVPlayback Component “wraps” aVideoPlayerinstance — so I wonder if you’re somewhat “mixing metaphors,” here.If you want to use a FLVPlayback Component instance, all you have to do is give that Component an instance name and use the instance name to reference its
contentPathproperty. You don’t need any of thatNetConnectionorNetStreambusiness.On the other hand, if you want to forego the Component — which is the focus of this article — you use the ActionScript I show at the very top along with a Video object.
August 28th, 2006 at 3:24 am
Very good for learning purpose.
August 28th, 2006 at 7:01 am
Ah, yes I got it now. Thanks alot mate!
Hadn’t quite understood how all this worked, but its running smoothly now!
Thanks alot for your time David! Well appriciated!
August 28th, 2006 at 7:36 am
Glad to hear it, Markus!
Enjoy.
August 28th, 2006 at 8:00 am
hemanshu,
Thanks!
August 28th, 2006 at 8:46 am
Hi agian!
When I load a new .flv-file with
videoPlayer.contentPath = _root.id + “.flv”;
my navigationbar won’t show up. This worked fine when I had a value for contentPath written in the Component Inspector, but not now when I load a contentPath with the actionscript. Have you any idea if I need to reload the navigationbar or something like that after I have loaded a (new) contentPath.
(My goal is to have a player that can load several different .flv-files. www.mysite.com/player.swf?id=1 opens 1.flv from the same dir. That works fine now, but when I do it like this, the navigationbar won’t show up anymore.)
Don’t know if it’s called navigationbar but couldn’t find any name for it.(The bar with the timeline and volume etc.)
August 28th, 2006 at 9:24 am
Markus,
I’m guessing you haven’t provided the skin in the Component Inspector. You can use both approaches, by the way: select the skin in the Component Inspector and set the
contentPathvia ActionScript. Or set both via ActionScript. Look up theFLVPlaybackclass in the Components Language Reference to see what all your choices are. Components are objects, just like anything else, and their classes follow suit, as described in my Objects: Your ActionScript Building Blocks article.September 1st, 2006 at 11:21 am
David, thanks so much for this code. I’ve read this whole thread and can’t seem to find what I need to modify… I am trying to use FlashVars so I can use one swf to play several different flv files. I have my embed and param tags set up correctly but I can’t figure outy what I need to put into your code…
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
videoPlayer.attachVideo(ns);
ns.play(”externalVideo.flv”);
I tried changing it to this:
ns.play(”openmediaPath”);
openmediaPath is my variable I define in the html. Am I using the wrong syntax?
September 1st, 2006 at 12:35 pm
Ryan,
You’re allllmost there! Notice that your
openmediaPathreference — which I assume is the variable you’re passing in via FlashVars — is quoted. Those quotes are killing it. You want to reference the value ofopenmediaPath, not the string “openmediaPath.” Get it?September 19th, 2006 at 2:22 pm
Hi Dave.
It looks like you have been very helpful to a lot of people, I think that is very cool. I hope that you can help me as well…
My issue seems to be strictly with absolute vs. relative paths.
When I use your code in my FLA and preview it in my browser it works like a charm. However, if I try to just view the SWF by itself OR even create an EXE, it doesnt work.
BUT, if I use an absolute URL to the FLV then it works in all scenarios. The problem is I am developing something to be deployed on CD-Rom. I will not be able to use an absolute path (nor do I think I should have to) to the FLV.
Any help is greatly appreciated…. TJ
September 19th, 2006 at 2:38 pm
TJ,
We’ll have to do a bit of troubleshooting, here. I pasted the exact code in my article into a new FLA with an external FLV in the same folder as the published SWF. Worked fine. Then I published a Windows EXE into the same folder and it continued to work. What version of the Flash Player are you publishing to? Have you tried this with another FLV?
September 19th, 2006 at 2:52 pm
WOW! Thanks so much for the quick response.
I just completed some more testing myself and noticed something…
Originally I was using Flash Pro 8, and publishing to Player 8. I noticed the security settings in the publish settings tab about local vs. network access and neither of them seemed to improve the outcome.
HOWEVER, I tried the same code with the same FLV using Flash MX2004 Pro, and publishing to Player 7 and it worked (almost). It found my FLV but only played audio… not video. I recreated my FLV using Flash MX2004 and it worked. I assume this was a codec issue with my original ver8 FLV.
The fact that I can get what I need with 7 is going to work with my current situation. But, I am definitely interested in trying to figure out what is going wrong with 8. I have tried a couple of different FLV’s and I also tried diff AS code (using the sample code from Flash 8 ). Again, it is always the same problem… preview in browser - no problem. SWF by itself or as EXE, it cannot find the FLV?
I really appreciate your assistance. Please let me know if there is anything else you need from me to help figure this bad boy out.
September 19th, 2006 at 7:30 pm
TJ,
That’s luck of the draw, I’m afraid. Sometimes I get overwhelmed with other things — but I’m glad I was able to respond quickly this time, too.
I’m interested in your problem, because none of this rings a bell with me. I didn’t have this issue in Flash MX 2004 and haven’t had it in Flash 8. I’ll try to help you if I can, but I need a bit more detail: are you on Mac or Windows? Write me offline — my last name @ quip.net — and I’ll take a look at your code. I’m on WinXP.
September 21st, 2006 at 6:25 pm
Note: For anyone following along, I took a look at TJ’s files. They work just fine on my machine, so TJ and I are baffled. This seems to indicate there’s something wrong specifically with TJ’s computer, security settings, Flash preferences, or some other TJ-only circumstance.
September 28th, 2006 at 4:37 am
Hi David,
Nice work!
I really appriciate what you are doing not only with flash but with helping ppl.
Now even im stuck up at one thing. I hope you can help me with this.
Im trying to buid a flv player which will pick movie file at runtime( like most ppl are doing) im using FlashVars its working good, but the trouble is that i want the seek bar to be able to point to prev sections and play from an earlier location ( something like youtube ).In my instance the slider doesnt appear unless the movie is completely played once. Im plainng to upload movies upto 30 mins duration and it would be difficult then. So do u have any ideas of how to make this work?
September 28th, 2006 at 10:30 am
Danish,
Thanks.
The trouble with what you hope to accomplish is that it isn’t possible to seek to sections of the video that haven’t yet loaded — unless you’re streaming the FLV from something like Flash Media Server. In my experience, the slider appears as soon as enough data have loaded … the FLVPlayback Component indicates load progress right in the slider, and it is indeed possible to seek among loaded frames. Are you using the FLVPlayback Component?
September 29th, 2006 at 2:35 am
Is it possible to load a FLV via nc.play(”file”) to a flvplayback component? I ask because there are methods i can use, such as seekToNavCuePoint with the component, whereas I can’t with NetStream. There’s more pros and cons as well. Any ideas?
September 29th, 2006 at 3:54 am
Hey David,
thanks for the help. it works, it was my mistake i wasnt putting the slider compnent correctly. but it works good now.
Although i was trying to compare the playback with you tube and was trying to find the best combination of bitrate and fps for encoding to flv, mine was always jerky. Then i ripped a video off you tube itself and tried to play that on my flvplayer and it was a lot better. The only thing is that it looks lower in quality (like antialiasing is turned on you tube and its off in mine). So this leads to anothr set of questions,
- What should be the optimal conversion parameters that the video plays decent enough?
- How is it possible that same file playes smooth on youtube’s player and looks grainey on my player?
- What possiblities does meta header hold, can this be credited to meta headers?
I know this is out of the topic … i can mail u if u want to discuss this outside..
Thanks again and keep up the good work.
October 3rd, 2006 at 2:18 pm
Wayne,
If you’re using the FLVPlayback Component, you can ignore the
FLVPlayback uses those classes along with additional code to handle the basics for you. That’s definitely one of the many benefits of using the Component, if you don’t mind the larger SWF file size and the requirement to publish to Flash 8 or higher. Just set the
NetStream/NetConnectioncombo.contentPathproperty of your FLVPlayback instance (via the Component Inspector or ActionScript) and you’re set.October 3rd, 2006 at 2:22 pm
Danish,
Glad you got it working!
Consider this article at Community MX, by Tom Green and Scott Fegette (free content):
FLV Datarate and Bandwidth… Demystified
You may also want to look at Scott’s Breeze seminar at the Adobe Developer Center:
Producing Video for Web
Between the two of those, you should find lots of useful information, even if it doesn’t answer every one of your questions.
October 13th, 2006 at 5:31 am
Thanks for the lines of actionscript sure does load quick.
I wonder how I can add the play, pause, stop buttons etc….
along with this actionscript.
Thanks Again
Enrique
October 13th, 2006 at 8:42 am
Enrique,
You’ll be glad to hear that your goal isn’t hard at all. In fact, that would make a great follow up to this article — so I’ll write about that in the next few days.
For now, take a look at the
NetStreamclass. In the example code, the variablensrefers to aNetStreaminstance. Methods are things an object can do (such as play), and you’re already using theNetStream.play()method. Check out the methods summary for this class in the ActionScript 2.0 Language Reference and you’ll see others useful to your goal. But again, I’ll write about this in an actual post very soon.October 13th, 2006 at 3:08 pm
Hi David,
You were so kind to reply to me back in April. Just wanted to let you know it was a MIME type issue of the FLV type not being recognized. Thanks a lot.
Thinking aloud, I guess I could do a URL-encoded variable in a link to load different FLV files with the one container swf, yes?
This would allow me to have a simple page with one SWF (video container) and a page of HTML links with a variable in the link such as 300monks.com/?video=artist1.flv
best
andrew
October 14th, 2006 at 7:12 pm
Andrew,
Ahh, those MIME types! Glad you resolved your issue.
You could certainly use a name/value pair to send information to the SWF. See this article for one example. Your suggestion is a bit different, in that your information is passed to the HTML document, rather than to the SWF itself. You’d need to use JavaScript to grab that query from the address, then pass it in via FlashVars, but it amounts to the same thing. Have fun with it!
October 23rd, 2006 at 4:50 am
hi david
thanks for a concise tute. clean and fun.
one question: can cue points with buttons to call those points be set using the video object with ns?
i know it’s a breeze with the FLVPlayback component and associated playback behaviors extension… but can it just as easily be built into your example with actionscript?
the reason i ask is i’m using a custom-built player with a certain shape/look… so using the FLVPlayback component isn’t an option…
-unless i’m mistaken & one can infact use the FLVPlayback component with custom buttons (& i don’t mean simple skinning
thanks!
s
October 23rd, 2006 at 11:54 am
sank,
I think you’re asking what Enrique did, recently. Have you checked out this articles companion piece, “How to Control Video (FLV) without a Component“? I think that gives you what you’re after.
The FLVPlayback Component has an API, just like the
NetStreamclass, so you can, in fact, manipulate it independently from its built-in controls. Just check out theFLVPlaybackclass in the Components Language Reference and note the available methods (things it can [be told to] do) and events (things it can react to). But my hunch is that you’ll actually want to manipulate theNetStreaminstance instead.November 1st, 2006 at 1:01 pm
Hi,
I am trying to find/code an interface like MediaPlayback (with the buttons and the bar etc.) to play a .swf movie clip. I don’t have .flv files but a bunch of
.swf movie clips and I am trying to have a nice interface to play them in.
Everything I searched and found so far is about playing .flv files
Any ideas/pointers will be highly appreciated.
Thanks!
Esra…
November 2nd, 2006 at 9:50 am
Esra,
I like your idea, but consider this: FLVs are linear … they have a starting frame and a final frame, and the idea is to move from the beginning straight to the end. SWFs can be linear, but many (perhaps most?) aren’t. SWFs, for example, have nested clips with their own independent timelines. SWFs may jump from a later frame to an earlier one, or pause while ActionScript handles a bit of animations — or the entire SWF might be animated by ActionScript. So how should a MediaPlayback-like interface work?
November 2nd, 2006 at 9:27 pm
Hi,
I have installed fms2 in my local pc and sucessfully stream the flv .
Now my problem is I do not able to create seek bar .
I load the flv like given [videoPlayer.attachVideo(ns);]
How to create a seek bar ? Any suggestion ?
November 10th, 2006 at 2:09 pm
Hello dave, i have a question. Im developing a video player in flash, but what i want is that when it’s open, it doesn’t download til the user clicks the play button. Is this posible??
Best regards
Daniel
November 12th, 2006 at 3:04 am
David,
Is it possible to use cuePoints when playing my FLV without a MediaPlayer or FLVPlayback component?
If so, can go give a little AS hint?
Thanks
November 13th, 2006 at 8:39 am
Replying to the last three …
Jack,
I have very little experience personally with Flash Media Server, so I’m afraid I don’t have a ready answer off the top of my head. A seek bar, conceptually, can be compared with a preloader bar. What you need are two values: the total duration of the video, and the current location of the video (that is, how far into the file the video has played). I believe FMS does provide total duration (progressive download does not — you’d have to supply the value yourself, as even the FLVPlayback Component requires). The
It’s on my list.
NetStreamclass does provide atimeproperty. Running these two numbers against each other gives you a ratio that you could then use to position a “handle” movie clip against a “track” movie clip. Not a bad idea for an article on this blog, actually.Daniel,
When you say “the play button” (emphasis mine), I wonder if you’re using something like the FLVPlayback Component, which has a built-in play button. If so, you’d have to do a bit of fancy programming to override some of the FLVPlayback’s default behavior. If you’re using the bare-bones approach described in the blog article above, you could assign the
ns.play("externalVideo.flv");to the Button.onRelease event handler of a button — that would do it.The Freaking Dutchman,
It should indeed be possible to roll your own cue points.
Given the
NetStream.timeproperty, comparable to theSound.position, you might experiment with the same approach outlined in my recent Cue Points for Audio Files article on the Adobe Developer Center.November 13th, 2006 at 11:57 pm
David,
I’m new to the actionscripting in video…after reading all the article posted here… i had tried them and it work fine to me, just that there is one more thing i can’t get it… how to load different flv into the same swf file?
Can it be done using like,say, after the first flv, go to next frame? please guide me a little.
Thanks
November 14th, 2006 at 12:58 am
David,
sorry to post two time…just to tell that i came out a solution already. here is what i have done. to me it’s work fine. If anything that can be improve pls correct me:
but now facing a problem… how to make the flv played according to vertical center…because all the movie not in the same size and also my video object…anyone can do it please guide me…thx
November 14th, 2006 at 8:41 am
Jeff,
That fact that you’ve come this far on your own should be an encouragement.
I’m not exactly sure what you’re after, but it looks like you’ve got a good start. The
NetStream.Play.Stopmessage appears when playback has stopped. You should do some experimenting to determine if this only happens when the file has reached its end (the video is over) or if it also happens when network congestion causes the video to temporarily pause while buffering. You only provided instruction for one of your twocasestatements, which means the resizing will occur both for theNetStream.Play.Startand theNetStream.Play.Fullmessages — not sure if that’s what you want, but it might be. If you’re resizing like this, I don’t see why you’d need to vertically center. Can you explain?November 14th, 2006 at 11:42 pm
well appearently i was making a fullscreen flash that run different movie sizes(example 1024×819, 1024×780)… well i got no problem with x size since all are in 1024…but because of y size not the same, i can’t make a “set” size for the video object…that’s why i was hoping to see if there is a way to make it play in the center(because my video object is 1024×768)
Anyway after i dig more into the tutorial while you are not around(since we are in a different half of the world)… i somehow found a solution to it…(and this previous script i posted seems to have some problem too)…
I have placed the files in www.geocities.com/zaslone
movie01.fla & movie.swf - the flash files(place flv named 01-05 will make
the swf work.
netstream.zip - flash files with sample flv included
the swf created can actually play the flv and when it finished it move to nextframe which another movie is loaded…
And if they can’t find the file, they will go back to first one(still haven’t think of how to make them skip to next frame instate of going back to beginning)…anything can be simplified pls tell
Anyway, thanks for guiding me.
…and sorry for a long post…
November 16th, 2006 at 2:07 pm
Jeff,
No worries about a long post. Sometimes my replies are pretty long.
You should be able to adjust the position of the Video object itself by adjusting its
_xand_yproperties. Generally speaking, the way to center something is to take the width (or height) of the parent object, divide that by 2, then subtract the width (or height) of the desired object, also divided by two.e.g.
When you say this …
… I don’t know if you mean video frames or movie clip timeline frames. If you mean timeline frames, just invoke the
MovieClip.gotoAndPlay()method (orgotoAndStop(), etc.).November 16th, 2006 at 5:14 pm
Hello! and thanks.
I’m building a custom class in as 2.0 that does a few things, and one of them is to set the contentPath of an existing FLVPlayer component instance. If I’m loading a movieClip, it’s easy to declare a MC variable in a method in my class file, then refer to it in my flash movie, but I’m baffled on how to refer to or type a var for the FLVPlayer component instance in my class file. I don’t really have to do it this way, but would like to know how!
November 16th, 2006 at 5:20 pm
zignorp,
How are you writing your class file? Are you extending the
MovieClipclass? If so, then your reference to the movie clip would be this — which is easy, as you’ve described. If not, then your reference to a movie clip would simply be its instance name, presumably passed into your class instance via the constructor or some other method (just as easy). In like fashion, you could either extend theFLVPlaybackclass or reference its instance name in the same way (this approach is called composition). Have you tried that? I’m not sure where you’re getting stuck.November 16th, 2006 at 9:41 pm
David,
thanks for the example you gave…I applied on it and it work just as i wanted now…
about this:
still haven’t think of how to make them skip to next frame instate of
going back to beginning
what i mean here is,like, if my timeline 4 frame. each of them have one different flv played(example 01.flv,02.flv,03.flv,04.flv)
lets say i forgot to put in 02.flv but i got 03 and 04, if i told flash to gotoAndPlay(1) if no flv of this name is detected(02.flv) …then they will skipped all the flv at the back(03.flv, 04.flv)and go back to frame 1.
i wonder if i wrote the script like, on the middle frame(frame 2, 3)
and putting this in the end of timeline
hope you know what i’m saying…
November 16th, 2006 at 10:00 pm
Jeff,
Aha, now I see what you’re doing. Well, honestly … I don’t see much benefit in using timeline frames to load your videos. That adds unnecessary complexity, don’t you think? Why not just use
NetStream.play()on your existingmynsobject to load another FLV when the first one finishes? That’s the great thing about these objects: you only have to instantiate them once — after that, just keep using the same objects. Does that make sense?November 17th, 2006 at 12:56 am
well i do try that at the first place…using one frame is that what you mean… some how that time i can’t get the things work well…i will try to give it another try…again thanks for guiding
November 17th, 2006 at 1:54 pm
Thanks David!
I am accessing my target movie clip through a method, which I’ll paste below.
I’m not sure what type to assign to the FLVplayer object, would this be a MovieClip as well?
function loadFilm(filmName:String, targetMC:MovieClip, filmID:Number, smFlv:String) {
smFlv = “flv320/”+filmName+”.flv”;
descSWF = “swfs/”+ filmName+”.swf”;
//playerFLV.contentPath=smFlv;
targetMC.unloadMovie();
targetMC.loadMovie(descSWF);
}
November 17th, 2006 at 2:33 pm
I just got it to work by extending the MC class AND adding it as a parameter of the function. I’m not sure why I had to do both, as the other target MC was working fine, but thanks for your help and education!
November 20th, 2006 at 9:29 am
To Jeff …
You got it. One frame is all you need. If that
NetStream.Play.Stopmessage is correctly indicating the conclusion of a video — and you’ll really have to experiment to determine that — then you can simply invokeNetStream.play()against thensinstance. With your approach, you’re essentially doing the same thing, except you’re completely re-instantiating thatnsobject, along with theNetConnectioninstance.To zignorp …
Glad you got it! I, too, am surprised that you had to do both, but hey … it’s working.
November 21st, 2006 at 2:02 pm
i love you, i’ve been looke everywhere for a stright foward solution to play flv’s without components, i thought i would never find anything. thanks for the help man it was much needed.
November 27th, 2006 at 8:55 am
Aaron,
Glad to hear it! Thanks!
December 1st, 2006 at 2:58 pm
I am using Flsh8 and was using the FLVplayback component but no video is present when using a web browser to connect to site, however when I open file using ftp client it works fine. I am using a relative path to call the .flv from .swf I tried the
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
videoPlayer.attachVideo(ns);
ns.play(”externalVideo.flv”);
and the same thing, any ideas what i’m doin wrong?
December 2nd, 2006 at 7:40 am
Chris,
My hunch has that you’re experiencing the phenomenon described here:
(Perhaps) Unexpected Point of View: SWF Defers to HTML
Unexpected “Gotcha” with Relative Paths in ActionScript
Make sure to read both.
December 11th, 2006 at 10:41 am
I’m using Flash 8 Pro and am new to video. I’d like my video to stream and play and at the end of the stream, I would like to go to a labeled frame in my animation and proceed.
I am doing that now with the timeline but that’s not working well.
Any help would be appreciated.
December 11th, 2006 at 3:02 pm
Just figured it out from your sample at top:
stop();
// Load the video
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
videoPlayer.attachVideo(ns);
ns.play(”videoname.flv”);
// Monitor the video
this.onEnterFrame = function() {
if (ns.time >= 30) {
gotoAndPlay(2);
;
delete this.onEnterFrame;
}
}
Thanks!
December 11th, 2006 at 3:11 pm
Joe,
Good for you!
I was going to direct you among those earlier comments for starters. I’ll probably write an actual article on the topic before too long, but in the mean time, way to go!
December 13th, 2006 at 6:36 am
hello ,
is it possible to load .mpeg,.avi,.mp3 as we are loading .flv through net stream.
and also i need the actionscript to find the format in perticular foder and then load in videoplayer. i mean can we write the code like if, else, condition to load differ formats which are avail in the folder.
Advance thanks
Anjan
December 13th, 2006 at 10:33 am
Anjan,
Flash loads more file types than ever, including JPG, GIF, PNG, MP3, XML, CSS, TXT, and probably a few more — but the only video format it supports is FLV. That said, I see you did ask about MP3. The older Media Components support MP3, but they don’t use the
NetStream class, as far as I know.December 13th, 2006 at 10:49 pm
Hey David, I want to compliment you on how well written and helpfull your website is. I especially enjoyed the article on catching fruit flys - if you have any similiar techniques for women - please let me know.
My flash problem is that I designed a flash website for my friend incorporating his video demos. I imported the files into .flv format, compressing them as much as I could.
I then inserted the videos into movie symbols - so that the movie will play on the frame when accessed. Everything works fine on my computer. However online they do not load. The box does not even appear.
- I checked the relative path article, however this doesn’t seem to be the problem in my case. The files are all located at
[bunch of URLs]
The “Loading” doesn’t actually work - I tried copy and pasting the code you had for the media.
“stop();
// Load the video
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
videoPlayer.attachVideo(ns);
ns.play(”PETERBdirectingREEL20072.flv”);
// Monitor the video
this.onEnterFrame = function() {
if (ns.time >= 30) {
gotoAndPlay(2);
;
delete this.onEnterFrame;
}
}
Unfortunately this only produces an error.
I am sorry I am not more knowledgable - I just graduated with a B.A., can’t find a job - so am trying to do webpages in the meantime. I hope that one day I can be in your position to mentor people like myself.
PS - this is the first USEFULL blog site I’ve come across - thanks again.
December 14th, 2006 at 3:48 am
Collin,
Haha! The latter doesn’t necessarily involve Saran Wrap with fork holes — at least, not in my experience.
This might actually be your problem, Collin. There’s nothing essentially wrong with embedding video content directly into a SWF’s movie clips, but doing so will definitely bulk up the SWF’s file size — and if you decide to go that route, then you don’t need the ActionScript from the above article; in fact, you wouldn’t need ActionScript at all.
The ActionScript above — with
NetConnection,NetStream, and so on — is something you can use when your video is external to the SWF. You don’t need the FLVPlayback Component or any other Component (I’m wondering if that’s what you meant by “the box”?) … the ActionScript handles the FLV loading by way of a Video object, as described way at the top. If by “the box” you mean the Video object, then that would make sense, because unless video is playing in it, a Video object can’t be seen.I think your best bet is to start with a fresh FLA file, free of anything but the bare essentials as described in the article. Make sure your Video object has the instance name
videoPlayer. Somewhere, you must have missed a step, so retrace your path and see if you can find where one of the footprints turns left at Albuquerque.December 18th, 2006 at 5:18 pm
Hi Guys,
Why can’t we use a relative path to flv file in ns.play() command. It appears to me that flv files must be on the same level as SWF (e.g ns.play(”myvideo.flv”) works, but ns.play(”\myFlvFolder\myvideo.flv”) would not )
Any thoughts would be appreciated.
Lnguyen
December 18th, 2006 at 5:31 pm
Lnguyen,
Ah, you’ll be pleased to know that you can, indeed, use relative paths!
In fact, if you think about it, the example in the original article shows a relative path — no path at all is a relative reference. The syntax of the path needs to be the same as for HTML, so flip those backslashes the other direction …
/myFlvFolder/myvideo.flv.Check out the “Unexpected Point of View” and “Gotcha” articles for important information on relative paths in ActionScript.
December 21st, 2006 at 4:25 pm
I’m using Flash 8 to use flv videos and interation that will be delivered on CDs. I’m using the FLVPlayer component to successfully play the video, but have not been able to get the embedded event cues to work. Can you help?
I tried using the code that was successful in MX2004, but it doesn’t work. Or I’m missing something. I’m in dire straights here. Please help.
Thanks in advance. I love you blogs. Great information.
Denise
December 21st, 2006 at 5:00 pm
Denise,
The FLVPlayback Component is new to Flash 8, so that may explain why your Flash MX 2004 code isn’t working. At its most basic, you’ll need something like this:
The variable
listeneris an arbitrarily namedObjectinstance. AcuePointproperty is created for this object and assigned to a function literal. This function acts on behalf of theFLVPlayback.cuePointevent and performs whatever you tell it to. Your FLVPlayback instance must “subscribe” the event to the listener, which occurs via theaddEventListener()method. The function receives a parameter arbitrarily referenced asevt, and it’s that parameter that will contain the reference to your cue points via its owninfoproperty. So, for example, to trace cue point names …December 22nd, 2006 at 3:52 pm
Hi David,
Great site, very helpful.
Quick pointer for those experiencing the “stuttering” or choppy playback / choppy audio when using the FLVPlayback component. SET your bufferTime property to something higher than the default 0.1s I set mine to 5 and that solved the problem. Technically this is only supposed to matter when you’re streaming and not doing progressive download, but I garuntee it makes the difference!
Now, the problem I’m having is a rather quirky one. I use the FLVPlayback component and feed the contentPath property dynamically using FlashVars. For some reason, on a few occasions when you load the video the seek bar scrubber, and the totalTime of the video fail to show up, but then if you reload it will appear again. The metadata is indeed properly encoded and as I said, it works sometimes (most times, but not others) It seems to me like the metadata info isn’t always loading, maybe the file playing before the metadata is populating the component is causing a problem? Anybody else run into this before?
Thanks! Great site.
January 1st, 2007 at 8:21 pm
Pooch,
I haven’t personally run into the problem you describe, so I can only take a wild stab at a solution. If you look up the
FLVPlaybackclass in the Components Language Reference, you’ll see that the class features anFLVPlayback.setSize()method. All v2 UI Components feature this method (if memory serves me), but the others inherit it from another class —FLVPlaybackstands apart in that regard.Anyway, this method allows you to resize the Component via ActionScript, and it’s a very different sort of resizing than what would happen if you simply set the instance’s
MovieClip._widthand_heightproperties (yup, theMovieClipclass also features in the mix, here). When Components resize, they initiate what I’ll call a “trickle down” effect, because it the resizing is passed along to all the sub-Components inside the main one, including buttons, sliders, and the like.So if you use ActionScript to set your FLVPlayback instance to its own current width and height, it might just shake loose the problem causing your occasional missing seekbar scrubber.
January 3rd, 2007 at 2:27 pm
I’ll give that a go and let you know what I find.
Thanks for the idea.
January 4th, 2007 at 1:59 am
I am using Flash 2004 for player 7. I am using MediaPlayback controller for playing FLV file. But there is some problem with seek bar. When i am scrubbing the seekbar and then play it’s not working fine. PLZ suggest me the correct way to use MediaPlayBack controller.
January 12th, 2007 at 2:33 pm
Hi guys,
I see there is a ton of help here on movie components but I am lost with this part of the actionscript needed for my project. I have a MediaPlayback component loading a .flv from a URL, My flash movie consists of 2 frames, the first one is a picture when clicked it takes it to the second frame which contains the component with the video, I just want to find out how I can tell the component to play frame 1 again when the video is done within it.
Thank you so much for your time,
I appreciate it,
Alex
January 17th, 2007 at 12:15 am
Hiya David - I’m working on an interactive trail map that utilizes an .flv file progressively downloaded in the first frame. I have set the actions in the first frame to:
stop();
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
FLVPlayback.attachVideo(ns);
ns.play(”wachugoog4.flv”);
this.onEnterFrame = function() {
if (ns.time >= 20) {
gotoAndPlay(2);
;
delete this.onEnterFrame;
}
}
due to the fact that the flv runs about 20 seconds; and at the very end, I’ve taken a screenshot of the final image, converted to movie, fade it out and transition to the actual trail map. Great in theory. It most often works, however, if you’re on a dial-up or simply have a weak signal, then your going to experience both choppiness AND it will go back to the first frame (beginning of .flv) which is of course, not what I want. How would you suggest preloading the .flv (without including playback controls) so it’s guaranteed to be fully loaded, runs through, fades out at end and is deleted.
Here’s the link to the current app to show you what I’m up to — any suggestions are greatly appreciated!!
http://www.northpoledesign.com/wachumap/wachu2.htm
Thanks again!! I look forward to hearing from you!!
Your site is bookmarked on my bookmark bar by the way
Best -
Senan
January 17th, 2007 at 10:13 am
To Alex …
The goal of being alerted to the end of a video clip is a popular one in comments on this blog, as well as a number of forums I frequent. The way(s) it can be approached depend on the object used. In this case, you’re talking about one of the older Media Components, so your best bet is to fire up the Components Language Reference and look for events of the
Mediaclass. You’ll find aMedia.completeevent, which is dispatched when, according to the docs, “the playhead reaches the end of the media.” Unfortunately, this wording is a bit unclear. By “playhead,” in this case, they’re talking about the seek bar (the slider) on an instance ofMediaPlaybackorMediaController, rather than the timeline playhead. Make sure your Media Component instance has an instance name, than use that in place of the “myMedia” used in the sample code for that event.Given the popularity of this topic, I intend to write a blog entry that steps through an example both for the older Media Components as well as the newer FLVPlayback Component.
To Senan …
I suggest you invoke the
NetStream.play()method, as you’ve done, then immediately invokeNetStream.pause(). Even though the video stream is paused, the FLV will continue to load. At this point, you may check theNetStream.bytesLoadedproperty against theNetStream.bytesTotalproperty in a loop to see when loading has completed. When that occurs, quit your loop and invokeNetStream.pause()a second time, which un-pauses the video.January 17th, 2007 at 11:20 am
Edited to incorporate my reply …
Senan,
I’m glad to help.
It’s important, though, that these comment entries don’t become the equivalent of a forum-style Q/A session — mainly because it would be too hard for me to keep up with them! If you see errors in your code, it’s often best to take a step back, then add one new line at a time, building up new expressions as you go. Add a bit, test; add a bit more, test.
Dig through the previous comments — April, 2006, to Mark — and you’ll see a few suggestions on how to test for the end of the video when using the
NetConnection/NetStreamapproach.MovieClip.onEnterFrameis an event that belongs to theMovieClipclass, which means it can be assigned to the main timeline, which is whatthisrefers to in this context. It’s really just a way to perform something repeatedly in ActionScript, which can be useful for checking loading values, for example. You could just as well use thesetInterval()function. The decision on when to use it and when to stop it (withdelete) depends on your needs. When you no longer need to perform an action continuously, it’s generally a good idea to stop.The
stop()function works very similarly to how theMovieClip.stop()method does. If you need to stop the timeline in which this code resides, you’ll need one of those two. Functions can be thought of as “free range” methods, in that they aren’t associated with a class (such asMovieClip). Check out the entry for each in the ActionScript 2.0 Language Reference for complete details, but in this particular case, the function stands on its own, and the method requires an object reference, such asthis.Careful! The
NetStream.pause()method doesn’t accept any string parameters, such as the quoted name of your FLV file (which is different, by the way, from the one specified in theplay()method). The only parameter it does accept is a Boolean. Here, too, the Components Language Reference is your best bet.I’m snipping the rest of your code, because you’re including a progress bar, which isn’t entirely necessary here. Could be useful — and I know the Help docs show it — but anything new like this should be ventured into with “baby steps.” Master one concept at a time.
All you absolutely need so far is to play, then pause an FLV stream. Play a stream first, to make sure that works, then add the pause line to make sure your results change. Does the video still play? If so, something is wrong. Work out each step along the way. Does it pause? Good, next step: test the
NetStream.bytesLoadedproperty.To do that, and to check for it repeatedly, you might use a
MovieClip.onEnterFrameevent. If so, then you may want to save your work, start a new FLA, and test just the enterFrame concept. Look up this event in the ActionScript 2.0 Language Reference, make sure you truly “get” what the event does — how to start it, how to stop it — before using it in conjunction with your existing video-related file.When you’ve mastered looping on a frame, bring that code into your video FLA and use it to trace the value of that
NetStreaminstance’sbytesLoadedproperty.In this way, with small but sure steps, you’ll eventually get to what you’re after.
January 17th, 2007 at 11:55 am
To Ravi Sharma …
Woops, didn’t mean to skip your question, Ravi. Unfortunately, I don’t think your comment gives me enough information to give you a solid answer. In any case, this particular blog entry has generated so many questions about the Media and FLVPlayback Components, I can see that a handful of articles on those topics would probably come in handy.
January 17th, 2007 at 12:13 pm
David - I really want to thank you for your patient & generous insights. I can understand & appreciate the desire to maintain a non-forum-like use of this environment. You’re providing a valuable resource here!! Thanks again and I will be putting the bib back on and vow to ‘progressively’ learn to walk before I….Flash [video]. All the best.
Senan
January 18th, 2007 at 11:58 am
Senan,
You’re welcome, and thanks for the kind words!
January 23rd, 2007 at 8:44 am
hi david. i am displaying several flvs on webpage at once - about 4. im using the custom UI FlvPlayback component at the moment, as it allows for easy skinning etc. here is the url:
http://www.itsourmovie.com/?q=taxonomy/term/5
However, problem is that each flv progressively downloads in the background, causing heavy bandwidth problems and the browser often just gets stuck and overloads. do you know of any way, that while still using progressive download, the video could just load the first frame - as a thumb, but *not* download in the background - i.e. just wait until the play button is pressed (obviously there would be buffer issues, but i can handle that). any play method would do, not just the flvplayback component. it seems very odd.. that adobe dont seem to provide a method to halt background downloading.. im being forced to look at Flash Media Server as a way of getting around the problem. Any thoughts appreciated.
January 23rd, 2007 at 9:53 am
if i may continue - looking for example at the flvplayback api docs:
LiveDocs link
and this:
http://www.adobe.com/devnet/flashcom/articles/flv_bestpractices.html
‘if video is over 1 minute, it should be streamed’. then it seems reasonable to conclude that adobe just dont really want to create progressive download tools in thier api.. as it will mean they cannot raise revenues by selling steaming software - i.e. FCS/FMS. there are plenty of ways that background downloading could be paused etc, or stopped to deal with bandwidth issues. the omission of such tools to me, seems *deliberate*.
humbug
January 24th, 2007 at 9:41 am
angurio,
It sounds like you’re frustrated — and that’s never fun, so I’m sorry to hear that — but on the bright side, you’re definitely not forced into purchasing Flash Media Server. True, it isn’t possible to natively halt background downloading in AS2, but if that’s the situation … work with what you’ve got.
If you can’t stop such downloads, the answer may be to refrain from starting a download until you need it.
The
FLVPlaybackclass, documented in the Components Language Reference, serves as your entry point in hos this component works. You may have to consult theVideoPlayerclass too, but ultimately, you’ll find that you can leave thecontentPathproperty empty in the Component Inspector, then supply that value with ActionScript layer. It is possible to “hijack” the controller buttons and have the Play button perform a load as well as a play (rather than just a play).And you’re not stuck with
If you use a Video object, as described in the original article, you can use your own buttons to come up with a user interface that behaves exactly how you want.
FLVPlayback, either.I respectfully disagree. Flash has evolved by leaps and bounds with each new release. ActionScript 3.0 provides considerably more control of all aspects of a SWF, including video. I know in particular that it’s possible to halt a load for audio — again, in AS3 — which is an important improvement over the way AS2 handled audio files. I experimented with AS3 and video yet, but I have high hopes. Many of the quirks in Flash relate to legacy compatibility issues.
There are ways to halt a given download, I agree. One of the “tricks” in AS2 is to load a known, very small “dummy” file to “kill” the other download. There are workarounds, to be sure. But again, my first approach in this situation would be to leave the
contentPathproperty blank — which means nothing loads in the background — then figure out a way to set that property via the Component’s skin buttons.January 25th, 2007 at 11:43 am
thanks david, very much! that was a great help. perhaps i will update here when ive sorted it all out.. so i can help other souls in a similar position.
thanks again.
January 31st, 2007 at 3:39 am
I am using the Flash 8 FLVPlayback and my a custom UI Seekbar from the components panel. Problem is that the seekbar is not disappearing when I set its visibility to false
mySeekBar._visible = false;
It seems that once the SeekBar instance has been associated with the FLVPlayback instance, it will remain on screen.
Basically my flash movie has 60 sections, some of which include a video. So I have the video components all set out on the stage and if there is no video for a particular section, I hide all the video components using the following code. I guess because I am only hiding and stopping the video, the seekbar still knows the video is lurking around. I do not know how else to get rid of the video. Possibly I can set the content path to empty but I got an error when I tried this.
my_FLVPlybk._visible = false;
my_FLVPlybk.stop();
play_btn._visible = false;
pause_btn._visible = false;
mySeekBar._visible = false;
Still, surely setting the visibility of the seekbar to false should hide it?
January 31st, 2007 at 4:43 pm
Hi David, thanks for your helps.
I’ve a problem.
I’m making an Interactive CD. For it, I’m using an executable SWF file from which I’m loading other external SWF files.
How can I put a FLV video in this case? I make ths question, because when I tried to put your code in a SWF file, the video doesn’t charge.
I hope that you can understand me because I’m not english-speaker.
Greetings,
Armando Picón
February 2nd, 2007 at 4:58 pm
To Steven …
The FLVPlayback Component — in fact, every Flash Component I can think of — extends the
MovieClipclass, so in theory, yes, you should be able to set theMovieClip._visibleproperty of that seek bar tofalse. I haven’t studied theFLVPlaybackclass in exhaustive detail, so I can only make guesses at this point. It’s possible that, as you suspect, the class “knows” when video is present and when it isn’t, and overrides (or resets) the_visibleproperty of that seek bar. I think yourcontentPathidea is a good one, but you said you got an error. What error was that?To Armando …
My initial hunch is that you’re simply supplying an incorrect path to your FLV file. If you can get your project to run successfully from your hard drive, you should be able to move all your files and folders as they are to the CD, and everything should still work.
I’ve run FLVs from a CD, so I know it’s possible. Don’t give up yet!
February 5th, 2007 at 11:16 am
Ok… I’m sure that “normally” works in a CD.
But, Will it works from an executable SWF that load other SWF in an empty movie clip?? Because, I’m trying with many diffent ways for write the path… and not work :’(
February 5th, 2007 at 11:21 am
… and if the problem is about “security policies” ???
February 6th, 2007 at 9:06 am
Armando,
I’m afraid I don’t know enough detail about your circumstances to answer with greater clarity. Flash Player security issues often get confusing, so I definitely recommend the official Adobe TechNotes there. At this point, you may want to do some trouble shooting — perhaps routing
NetStream.onStatusmessages to a dynamic text field so you can look for possible errors while the SWF runs inside the Projector.February 7th, 2007 at 2:14 pm
hi david,
fantastic blog…thanks so much for the info.
i have used your code for setting up a video to play in a small banner. on my desktop it’s working perfectly. (i’ve also found a good way to solve the question of how to let the swf know when the video is done playing, which hopefully will be of service to you and your readers.)
the problem i’m having is that when i post it on the web, the video is not playing right away. as you can see from the code the video is supposed to begin when the invisible button is clicked…however, the browser is displaying an error message, and then about 10-15 seconds later the video begins to play. (there is intentionally no audio in this video.)
any thoughts as to why it would play correctly on the desktop but not on the web?
thanks so much for any help,
colin
here’s the code i used:
fscommand(”showmenu”, “false”);
var my_nc:NetConnection = new NetConnection();
my_nc.connect(null);
var my_ns:NetStream = new NetStream(my_nc);
videoBox.attachVideo(my_ns);
my_ns.setBufferTime(35);
my_ns.play(”gopher_small3.flv”);
my_ns.seek(0);
my_ns.pause();
my_ns.onStatus = function(info) {
if (info.code == “NetStream.Play.Stop”) {
my_ns.seek(0);
my_ns.pause();
_root.gotoAndPlay(”complete”);
}
};
btn_play.onRelease = function(){
my_ns.play(”gopher_small3.flv”);
mcPostit._visible = false;
_root.gotoAndStop(”play”);
};
stop();
here’s the file up on the web: (it should start when you click the yellow note…if you’re patient you’ll see it takes 10-15 seconds to begin rolling.)
http://teakedit.com/testing/
February 7th, 2007 at 2:17 pm
hmmm,
now it seems to be working pretty well…maybe because it was cached for me. could it have to do with the buffer time?
(i tried to check that, which is why the code i sent you has a BufferTime of (35)…the actual version on the web has a BufferTime of (5).
just trying to clarify,
colin
February 8th, 2007 at 8:22 pm
colin,
By setting a buffer time of 35, you’re asking Flash to hold off actually playing the video until 35 seconds have been loaded. The default value for this property is 0.1 (one tenth of a second). So that almost certainly explains the delay. And you betcha, FLVs cache just like other files, so you’ll have to clear your cache each time in order to test afresh — or use a random number to “trick” Flash out of it.
Thanks for the compliments!
February 13th, 2007 at 6:23 pm
Hi david, i have little experience in flash and i was wondering if you could tell me how to get the movie to repeat.
Thank you.
February 13th, 2007 at 6:59 pm
Arvid,
By “movie,” most Flash developers mean a FLA or SWF, but because you posted to this FLV entry, my hunch is that you’re asking how to replay the FLV video file. If that’s it, simply invoke the
NetStream.play()method again. Alternatively, you may invoke theNetStream.seek()method; in any case, theNetStreamclass is your best bet.Check it out in the ActionScript 2.0 Language Reference to see what your options are — properties are characteristics the object has, methods are things the object can do, and events are things the object can react to. You may want to read Objects: Your ActionScript Building Blocks for a general overview on classes, if these terms don’t feel especially comfortable yet.
March 3rd, 2007 at 12:20 pm
hey David,
Great site, with awsome support!
Ive made a php script which randomly pick a filename from a .xml file. Now i want the file to be played in my movie. I was thinking of something like this: - but I cant get it to work.
sti = “http://www.mysite.com/kaspar/web/test.php?funktion=geturl”
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
videoPlayer.attachVideo(ns);
ns.play(sti);
My plan is to run the thing on a local network with php installed, which ‘method’ would you think could be the most appropriate ?
FLVPlayback og videoPlayer or something different? videoclip size is about 10mb pr clip.
Kaspar Hansen
March 6th, 2007 at 8:04 am
hi
i wonder how can i play flv with buttons? i have 3 videos and 3 buttons that will load the flv into a tv i created…i cant get the buttons to work
March 6th, 2007 at 8:35 pm
To Kaspar …
I have two thoughts. First, why not use Flash to load the XML itself? See the
XMLandXMLNodeclass entries in the ActionScript 2.0 Language Reference. It’s likely you could do the whole thing without PHP, though there’s nothing wrong with your PHP approach. My second thought — actually, this is an observation — is that you’ll need to load that PHP data via something like theLoadVarsclass. Your idea is entirely feasible, but that isn’t the way to set variables to external values in Flash.To helena …
Hi! Have you seen the “How to Control Video (FLV) without a Component” article on this blog? That may give you a few pointers.
March 20th, 2007 at 5:04 am
Hi David
Thanks for the blog and your work on this topic. I have found it very useful. I am wanting to test for when the video has finished so I can trigger a new event. You mentioned this (below) earlier last year and was wondering if you ever got anywhere with it?
Great site:)
March 20th, 2007 at 6:55 pm
Hi David,
My video plays fine but there’s no audio at all. Here’s the code I used. I don’t think I missed anything major.
stop();
my_NC = new NetConnection();
my_NC.connect(null);
myStream = new NetStream(my_NC);
myVid.attachVideo (myStream);
// Set the buffer time
myStream.setBufferTime(100);
btnPlay.addEventListener(”click”, playFLV);
function playFLV(){
myStream.play(”1PExtro.FLV”);
}
March 20th, 2007 at 7:46 pm
To Phil …
Do you know, I have pursued that question on a handful of occasions since I wrote this entry … in all this time, I still haven’t hit what I feel is a definitive answer — but enough colleagues have taken to the
onStatusapproach, on their own, that “close enough” may just have to do.Thanks for the patience, and I’ll make this topic the subject of my next blog entry. Promise.
To Darren …
Your code looks fine, so I’m curious, too, why your audio doesn’t play. The first thing I would do in this case is run the FLV file on its own (say, with Martijn de Visser’s FLV Player) to make sure it actually has audio. If it plays fine, then I’d check for any ActionScript in my FLA that may be setting the volume down in general.
March 22nd, 2007 at 9:03 pm
I’m trying to use your technique but I get only audio, no video (on Mac 10.3.9, flash player
The difference between your technique and mine is thatI split up the code to different areas. I have this code on the main time line:
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
The I have on the stage a movie clip with a button inside it. The button has this code:
on (press) {
_root.videoPlayer.attachVideo(ns);
_root.ns.setBufferTime(5);
_root.ns.play(”office.flv”);
_root.videocover.gotoAndStop(’vis’);
gotoAndStop(’on’);
}
So this only gets me the audio part of the video. A google search turned up nothing, I’m at a loss as to what to try next.
March 22nd, 2007 at 9:18 pm
Michael,
Even though your code has only changed a bit from my suggestion, the fact that it has changed at all may be enough to merit some testing. When inexplicable things like this crop up, I generally take a step back and start again with the basics: start from a place that I know works correctly, then slowly re-add the new stuff.
I recommend, in any case, that you put the first two lines of your
on()event handler with the earlier code. Here’s why. There’s really no need to attach the video or set the buffer time more than once. If someone clicks this button repeatedly, it performs more ActionScript than it needs to.So I would create a quick new FLA, put only the code necessary — not even the button, yet — and make sure that works. If it does, add a button and move just the
play()line to that button. Then add thegotoAndPlay()lines one by one, testing each time. If it doesn’t work, even from the most basic approach, play the FLV independently in a stand-alone FLV Player (I happen to use Martijn de Visser’s) and make sure the FLV is properly functional.March 22nd, 2007 at 9:37 pm
Thanks david, I got it working a bit better. I took these lines out of the button code and put it on the main time line:
_root.videoPlayer.attachVideo(ns);
_root.ns.setBufferTime(5);
removing the _root. parts of course. Now the video loads. Only one problem left! I have a movieclip on the main timeline with this code (to stop/unload the flv):
close_btn.onRelease = function(){
_root.ns.close();
};
stop();
and a button called close_btn in the movie clip. This succeeds in stopping the video but it just freezes and does not disappear from the stage. I tried _root.ns.clear() as well but no dice.
March 22nd, 2007 at 9:46 pm
Michael,
Almost there! In addition to the
NetConnectionandNetStreamclasses, you’re also dealing with a Video object, so take a quick look at theVideoclass and you’ll find a_visibleproperty.March 22nd, 2007 at 10:06 pm
Thank YOU!!!! (Marry Me) lol
adding _root.videoPlayer._visible = false;
worked perfectly!
March 22nd, 2007 at 10:12 pm
Michael,
haha Awesome!
March 26th, 2007 at 9:38 am
Hey David,
I’m having an issue with extracting the code to play an flv into a class. I have a function call from the fla as such:
var vid = _parent.createVid(video_mc,”flv/intro.flv”);
vid.playFile();
This code calls a method from my starter class (attached to a parent swf) with this code:
public function createVid(mc:MovieClip,file:String){
var vidSettings = new classes.VideoSettings(mc,file);
return vidSettings;
}
This instantiates my ‘video’ class that i’m hoping would initialize everything to play the flv back. Here is that class code:
class classes.VideoSettings {
private var buffer:Number;
private var video:String;
private var video_mc;
private var mc:MovieClip;
private var stream:NetStream;
public function VideoSettings(mc:MovieClip,file:String){
this.mc = mc;
this.buffer = 3;
this.video = file;
this.init();
}
private function init(){
var connection_nc:NetConnection = new NetConnection();
connection_nc.connect(null);
this.stream = new NetStream(connection_nc);
this.stream.setBufferTime(this.buffer);
}
public function playFile(){
var vid:Video = this.mc.videoScreen;
vid.attachVideo(this.stream);
this.stream.play(this.video);
this.stream.onStatus = function(infoObject:Object){
trace(infoObject.code);
if(infoObject.code == “NetStream.Play.Stop”){
//skip_btn.onRelease();
}
}
}
}
When i trace out the status, i see that it is ‘playing’, but it actually just gets frozen on the first frame of the movie. I can even implement stream.seek(x) and jump to points in the movie, but it doesnt play back. Any help you can offer would be much appreciated. Thanks!
Tito
March 27th, 2007 at 9:53 am
Tito,
I’m assuming the movie clip referred to in this line …
… actually contains a Video object, right? If so, your approach shouldn’t be a problem; and yet — and this is the “fun” of programming, right? — seemingly inexplicable problems do crop up. I don’t immediately see an error with your ActionScript, so in a case like this, I would take a few steps back and gradually build up again to ActionScript in an external class file. Take very small steps and make a test with each new line of code. If you’ve made a mistake, you’ll likely catch it this way. I would also test the FLV itself. Was it properly encoded? Have you published to a high enough version of the Flash Player for the codec you’re using?
March 27th, 2007 at 12:11 pm
Hey David,
Thanks for your quick response! In regards to your questions:
‘this.mc’ is referring to a movieclip on the stage that contains a video object named ‘videoScreen’.
The flv itself is fine, since if i extract the code in my class functions to play the flv and place it within the fla, everything works fine. I’ve traced out each section of the methods and everything is being passed as it should and reaching the desired methods. The video even gets started/loaded, but as i mentioned previously, just hangs on the first frame of the movie
This is very confusing to me, since I dont see anything that could be causing it…
Do i have to make my class extend something like ‘movieclip’ ? i’ll keep testing, and post if i come up with any results. Thanks again for your assistance, I know many others as well as myself appreciate it
Tito
March 27th, 2007 at 1:39 pm
Hi David, this is my problem. I want to load the .flv file from another location relative to the html that has the .swf link. I’m using swfobject.js and passing my .flv filename using addVariable(). The swf file (which is the video player) is in a completely different location than the html but the flv file is in the same directory as the html. Unfortunately, Flash 8 decides to make the “contentPath” (or using your way, it doesn’t make a difference) to the .flv file relative to the .swf file and not the html. As a contradiction, if you use a skin for playback buttons, etc… it looks for it relative to the html and not the swf. That of course is fixable because Flash 8 let’s you specify your own custom url to the skin. But I need my contentPath to be relative to the HTML and not the .swf file that contains my player! Ugh. I don’t see any way of doing this yet… And why the heck does Flash 8 treat “contentPath” and skin paths differently?
March 27th, 2007 at 1:48 pm
Matt,
That is a weird phenomenon, isn’t it? For anyone else following along, I made a few observations on the same topic in “(Perhaps) Unexpected Point of View: SWF Defers to HTML” and “Unexpected ‘Gotcha’ with Relative Paths in ActionScript”.
Fortunately, you should still be okay. Use
addVariable()to pass in the location of the FLV, but don’t include a path. Because FLV paths, oddly enough, are associated with the SWF, use theMovieClip._urlproperty to determine the SWF’s location, then keep only the first part of that string (up to the last slash) with, say,String.substr()… then append your FLV, as passed in, to that path.March 27th, 2007 at 2:43 pm
Maybe I misunderstood you but I don’t want to know the SWF’s location. It would be say here: /scripts/videoplayer.swf. But my html file (i.e. “how-to-multiply.html”) that embeds it is here: /courses/math1/ as well as the .flv file: “how-to-multiply.flv”. Let’s pretend I’ve got tons of courses like this and various .flv files in them. I want my videoplayer.swf to find “how-to-multiply.flv” in /courses/math1/ and not /scripts/. So I set contentPath=”how-to-multiply.flv” with addVariable() & actionscript and right now I’m getting 404 errors that say it can’t find /scripts/how-to-multiply.flv. My .flv files are stored along with the .html files that embed the videoplayer.swf and I can’t figure out how to make it load the .flv files from there except by saying contentPath=”/courses/math1/how-to-multiply.flv”. That’s a pain because it should look relative to the html file anyways and not from the swf. Did that make sense?
March 27th, 2007 at 3:12 pm
Matt,
Sorry, man. You understood me just fine — I goofed! I mistakenly thought the
_urlproperty would display the location of the HTML file, given the path wackiness we just discussed, but it shows the location of the SWF.Is there a reason not to use absolute paths?
If they have to be relative, you can always use
../to back up a folder.March 27th, 2007 at 3:48 pm
Thanks for your input. Absolute paths will work but obviously if I restructure the directories, I’d have to change them all. I’ve posted in Adobe Webforums but I see that you’ve responded there as well
Maybe Adobe will see this and fix it as I’m pretty sure it’s a bug.
March 27th, 2007 at 4:09 pm
Matt,
Hard to say if it’s a bug, but imagine … if they change this behavior in future Flash Players, all the content out there that currently works will fail. So it’s a dicey situation.
If you think in terms of your SWF’s location, though, you can backtrack to where the FLVs are with
../, so give that a shot. Good luck with that!April 1st, 2007 at 11:45 am
Tito,
Woops, I missed your earlier reply from March 27. The only time you need to extend
MovieClip(or any class, for that matter) is when you need most or all of that class’s functionality in the new class. Imagine aPetbase class. Instances ofPetcan walk, eat, and make noise. If you’re writing aDogclass, it probably makes sense to extendPet, because your dog objects will need to walk, eat, and make noise. By extendingPet, those objects can already do all of those things. In addition, yourDogclass will add functionality to chase sticks.In my view, your class doesn’t need to extend
MovieClip… what you’re doing here, in a sense, is transferring timeline code into an external file. There’s nothing about class files per se that would change the way video is displayed. Unfortunately, nothing immediately jumps out at me in your sample code, so I’m kinda scratching my head too.I hate to use the following as an excuse, but the last several months have been absolutely insanely busy for me. I’m almost finished a Flash book for friends of ED for this summer, so for better or worse, I’ve had to limit my blog and newsgroup replies to answers that spring to mind immediately.
April 17th, 2007 at 10:41 am
I know this is a basic issue but I can’t figure out how to Pause or Stop the FLV streaming on load. I don’t want it to just play, I want the user to click play. How can I do that in the script? Thanks in advance for your patience.
var rtmpRoot, instance, file, type;
var x:XML = new XML();
x.ignoreWhite = true;
x.onLoad = function(success) {
if (!success) {
trace(”Cannot load XML”);
} else {
trace(”Loaded”);
//trace(this);
file = this.childNodes[0].childNodes[0].childNodes[0].toString();
trace(file.substr(file.length - 3, 3));
type = file.toLowerCase().substr(file.length - 3, 3);
trace (type);
}
};
x.load(”movie.xml”);
April 17th, 2007 at 7:31 pm
Jeff,
When you stay “Pause or Stop the FLV streaming on load,” do you mean in response to the
XML.onLoadevent? If so, you would reference yourNetStreaminstance in theonLoadhandler — the function in your code above — and invoke, say, theNetStream.pause()method.Does that answer your question? If not, ask again and I’ll try again.
May 8th, 2007 at 11:38 pm
Hi David,
I experienced a problem with video playback which was very similar to what TJ described above. Searching for solutions I came across this page.
As it turns out, the solution to the problem was fairly simple:
I have a hebrew version of windows and I was working on files that were located on my desktop. Foreign language Windows versions give the Desktop a name in the local language which means that the absolute path to my FLV file included incorrect characters.
Once I moved the files to an English-Only path (i.e. C:/MyPresentation/myVideo.flv) everything worked. Perhaps TJ’s files worked on your computer and not his, because he works on a non-english OS.
May 10th, 2007 at 8:03 am
Hi David,
I am writing a large piece of education software for schools. It is mostly written in Flash but uses Director to handle the FileIO. After 9 months of development one of the final problems that I have is that the FLV files will not run when the application (which is an EXE) is run over a UNC path.
The path to the FLV needs to be absolute as the software allows schools to install ‘resource packs’ (containing FLVs, JPGs etc, etc) on any server and the application pulls in the resources from these different locations. All the other ‘resources’ load in fine (i.e. the SWFs, MP3s and JPGs) but the FLVs will not play. I am using the FLvPlayback componant and I assume that I am hitting a security issue with the playback of FLV files across UNC paths (which I assume Flash treats with the same security as Cross-Domain). Is there a solution or is it the case that there is no way to playback an FLV file across a UNC path.
Kind Regards,
James
May 11th, 2007 at 11:37 am
Jeff: I was having this same problem. It’s actually really simple to solve. You have to set the “autoplay” parameter to false. And that’s it.
After your flv is positioned on your stage, select it. In the properties window, there is a tab for parameters, under parameters you’ll see the auto play set to true. Change it to false.
May 12th, 2007 at 7:37 am
Is it possble edit the code to have a button on frame 1 play the video component say on frame four?
May 13th, 2007 at 8:56 pm
To Ilan …
Interesting. I certainly hadn’t thought of something like your suggestion for TJ’s files. I do remember that they worked just fine on my machine, so it’s hard to say if it was a language-level (or character-level) issue, but you’ve raised a thought-provoking point.
To James …
I don’t know the answer to this personally, but I’ll check with a few colleagues who may know. I’ve noted your personal email address and will reply there.
To Brian …
That may just be it if Jeff is using the FLVPlayback Component. Good thought! I’m curious what the XML connection is, so I hope Jeff writes back.
To Tony …
That is possible, but just have to make the “connections” work. For example, if the button is on frame 1 and the FLVPlayback Component (or any Component) is on frame 4, then they don’t exist at the same time. One of the ways you can get around this is to put the Component on frame 1 along with the button, but set its alpha or visibility to zero. It has to “be there” where the button is in order for ActionScript to be able to talk to it. But then you could use the button to a) send the playhead to frame 4 and b) turn the Component’s visibility back on.
May 16th, 2007 at 4:30 pm
This article is just what I was looking for. And it has worked great… on my local disk. I have not been able to get it to work when I move everything onto my server. Is there some reason the .flv files won’t load once they are on a server?
Thanks!
May 16th, 2007 at 4:59 pm
Nevermind - Called my webhost and they added the appropriate MIME type.
May 16th, 2007 at 5:25 pm
craig,
Glad to hear it!
May 17th, 2007 at 1:59 am
how can you make the video stop once you leave that frame. I have the video component in frame 4 and when I click the menu button to return to frame 1 lets say. I can still hear the media playing, if i return to frame 4 i can’t see the media, but if i click on a button to play that or another media then it’ll stop but only to reload the media into the component.
May 17th, 2007 at 10:46 am
once l leave that frame where the component is. I can still hear the audio. Is there a way to make it stop once you leave that frame. Other than that this script is amazing, thank you so much for it.
May 17th, 2007 at 2:17 pm
Tony,
When you say “video component,” do you mean the FLVPlayback Component? If so, check out the
FLVPlayback.stop()andFLVPlayback.close()methods in the Components Language Reference. I would suggest invoking one (or both) of those in your FLVPlayback instance before leaving the frame. If you’re using the non-Component approach, consider invokingNetStream.close()on yourNetStreaminstance before leaving the frame.May 31st, 2007 at 12:11 pm
hi david,
i am new to work with flv. if i got a flashing logo to act as a simple preloader (no number loaded that kind of fancy things i need) for my streaming flv, what is the actionscripts to tell my logo to dismiss and call my total loaded flv to appear and start play? my flv is attached with the default FLVPlayback skin for streaming already. the logo is a simple movie clip within the fla….
thx for your help!
May 31st, 2007 at 1:52 pm
beryl,
The answer to your question depends on the mechanism you’re using to detect that the FLV has loaded. You’re using the FLVPlayback Component, so that means you could be using the
VideoPlayerclass, which the Component wraps …VideoPlayerfeaturesbytesLoadedandbytesTotalproperties, so if you’re checking those in anonEnterFrameloop, you could simply issue aplay()action whenbytesLoadedis greater than or equal tobytesTotal.Does that steer you in the right direction? If not, let me know.
June 29th, 2007 at 9:57 am
I’m not sure what I’ve done wrong, but all I get are error messages and no video:
**Error** Symbol=Symbol 329, layer=video, frame=1:Line 16: Statement must appear within on/onClipEvent handler
var nc:NetConnection = new NetConnection();
**Error** Symbol=Symbol 329, layer=video, frame=1:Line 17: Statement must appear within on/onClipEvent handler
nc.connect(null);
**Error** Symbol=Symbol 329, layer=video, frame=1:Line 18: Statement must appear within on/onClipEvent handler
var ns:NetStream = new NetStream(nc);
June 29th, 2007 at 10:48 am
Will,
Those errors mean you’re trying to attach code directly to an object — I’m guessing the Video object — rather than in a keyframe. Code that is directly attached must appear within either an
on()event handler or theonClipEvent()event handler, which isn’t how I wrote the blog entry’s ActionScript. Put that code in a keyframe, and you should be all right. See my “museum pieces” article for additional notes onon()andonClipEvent().July 14th, 2007 at 8:50 pm
David,
I am trying to load a list of movies to play from an XML document. The XML loads into Flash just fine but I can’t seem to pass the variable to the netStream.play() function.
Here is my code…
//create global sound object
globalVolume = new Sound();
//new netconnection object
connection = new NetConnection();
connection.connect(null);
stream = new NetStream(connection);
video.attachVideo(stream);
stream.setBufferTime(0);
//since the movie is playing set the state to true
playstate = true;
//load the XML file
var videoPlaylist = new XML();
var videoPaths = new Array();
videoPlaylist.ignoreWhite = true;
videoPlaylist.load(”videopath.xml”);
videoPlaylist.onLoad = function(success) {
if (success) {
trace(”Loaded XML file successfully”);
currentVideo = videoPlaylist.lastChild.firstChild.childNodes;
//populate the array storing the paths to video files
for (i=0; i
July 16th, 2007 at 8:21 am
Sean,
Unfortunately, your code seems to have been cut off — looks like the
<character may have been the culprit. Have you verified that whatever variable is intended to hold a file location actually holds that location (i.e., have you usedtrace()to see what you’re sending theplay()method)?July 18th, 2007 at 1:59 am
First off I’d like to thank you for all the great stuff on your blog. Two thumbs up !
Now my question is a little off this topic but I was wondering if you could help me before I have no hair left because I’ve pulled it all out. Seriously… I’ve been trying to find an answer for months now and have searched and searched and searched some more. In fact it’s 2:40am and I’ve been looking for a solution almost 6 hours tonight and that’s just today.
I’m trying to make a Video Poster for my blog. They are movie posters with a trailer. I want them to be all contained in one SWF file. Figured most of it out but now the file downloads the whole FLV video every time someone visits my page. This is blowing out my Bandwidth to the point where I have five File Storage accounts and have to constantly change my code to a new one every time my bandwith is exceeded.
I’m using the video player from Adobe with the skin on auto hide and using Progressive download. You can see it on my Website.. The Ratatouille one. The others are using the Flowplayer which is OK but not really what I need because I can’t contain the poster in the SWF file and Flowplayer together.
So if by chance you could spare a moment to help me before I’m bald I’m sure my girlfriend will thank you. : )
P.S. Here is the FLA file if that helps.
http://hbkitty3.googlepages.com/Ratatouille_Video_Poster.fla
July 24th, 2007 at 7:07 pm
David,
I am trying figure out how to play an FLV file once and then at the end of the flv video have it goto the next scene. I seem to figure this out and I am more of a designer and don’t really understand a lot of actionscript.
Thanks.
Brad
July 25th, 2007 at 11:59 am
To Colin …
What I would suggest, in this case, is to drop the skin (I’ll tell you why in a sec) and leave the
sourceparameter empty in the Parameters tab of the Property inspector (in the AS2 version of FLVPlayback, the corresponding parameter iscontentPath). If the FLVPlayback Component doesn’t know which FLV to load, it can’t start eating your bandwith.Add your own button (this is why the skin has got to go) and have that button call your FLVPlayback instance by its instance name ‐ provide an instance name via the same Parameters tab — and have your button invoke FLVPlayback.source on the instance name, then
FLVPlayback.play(). Assuming the instance namevideoPlayerand a button with the instance namemyButton…To Brad …
Check out “How to Determine the Completion of a Flash Video (FLV) File,” and instead of using
trace(), invoke an appropriateMovieClipmethod on the main timeline (might begotoAndPlay(), for example).July 26th, 2007 at 4:24 pm
Hi David,
Glad I found you, and thanks for your tireless explanations… I tried getting this together - followed your instructions as written. I can hear the audio for the clip just fine, but I can’t see any video. Do you have any idea why I would be able to hear the video, but not see it?
July 26th, 2007 at 5:47 pm
It looks like my .flv files were at fault… I reprocessed them without editing them first and it’s working. Sorry to clutter up your killer flash blog.
July 30th, 2007 at 6:33 pm
Andrew,
No worries! Glad you found your answer, man.
July 31st, 2007 at 1:04 pm
I guess this means the Adobe Skin is out eh. What a shame. I kind of liked the button with the glow and everything. It’s very stylish. Is it possible to use just the button from the Adobe Skin ? Do you know of any good free tutorials on creating your own Progressive Download Video Player ? Didn’t you have one ? I’ll look about. Thanks a million. : )
July 31st, 2007 at 9:20 pm
Colin,
If you like the Adobe skin, have at it! I personally prefer the non-Component approach because of the file size savings. It’s certainly possible to use just a single button from the original skin set (see the FLVPlayback Custom UI folder in the Components panel of Flash 8 or the Video folder in the Components panel of Flash CS3) — in that case, you’d use the FLVPlayback Component with the “no skin” setting, then wire up the stand-alone button(s) as described in the “Skinning FLV Playback Custom UI components individually” heading of the ActionScript 2.0 Components Language Reference. If you’re using ActionScript 3.0, you don’t even have to go to any trouble: the stand-along parts sense each other automatically and just work.
August 3rd, 2007 at 4:47 am
Hi David,
I am using the FLV Component (Flash 8) in an app that allows the user to open and view multiple FLVs (it’s all contained in 1 SWF though) that are progressively downloaded. I am finding that when the component is removed from the stage the FLV continues to load in in the background. This means that, once the user has clicked on a few different FLVs things start to load in really slowly becuase Flash is loading all the other FLVs in the background! I have tried using myFLVObject.close() but it seems to have no effect.
If you launch and FLV, close it, wait a few minutes and then launch it again you can see that the whole thing has loaded in! Do you know of a way to stop this happening?
Thanks for any help you can offer!
James
August 5th, 2007 at 8:08 pm
James,
The Components Language Reference doesn’t list a
close()method for theFLVPlaybackclass. As it turns out, there is anFLVPlayback.closeVideoPlayer()method, which might be what you’re after, but you would have to invoke that method on an instance currently present on the Stage.I agree, it’s pretty weird that your FLVPlayback instance continues to load content after it’s been removed, but I’ve seen the occasional phantom object reference in Flash from time to time, especially when the scenario deals with something as complex as FLVPlayback.
Check out the methods specific to the
FLVPlaybackclass again and experiment with those before removing your FLVPlayback instance. Let me know if that does it for you.August 13th, 2007 at 9:46 am
I’m afraid I’m new to all this and I’ve yet to get it to work. I just wish I could find a tutorial that actually works. I’ve looked everywhere but can’t find one that works for Flash CS3. You’d think a tutorial on making custom video players would be popular seeing that every media rich web site has them. Thanks for taking the time to write a reply. You’re like the only one. It means alot.
August 14th, 2007 at 10:16 am
I have been successful at implementing flash video on our site with the new import feature in CS3. Except I only want the video to load when clicked on. Im trying to save bandwidth. Any help would be appriciated.
August 14th, 2007 at 11:30 am
Hi David,
I’m afraid my post is not related exactly to yours but I was just wondering if you had come accross this issue and could help me out.
I am using an instance of a MediaPlayback component to dynamically load a specific flv whose name is passed as parameter: myMediaPlayback.setMedia(myFlv, “FLV”);
The ‘Automatically Play’ property is ticked off, as I want the user to press the play button to get it started. This is almost working, however, some of the audio plays very briefly and then it stops. How could I prevent the audio from playing at all until the play button is clicked? Thanks very much for your time.
August 14th, 2007 at 3:14 pm
To Colin …
The example I’ve shown in this particular blog entry is based on ActionScript 2.0, which is available in Flash CS3 if you configure your publish settings that way for the FLA in question (see File > Publish Settings > Flash tab). If you’re looking for a way to load FLV video into a Video object in ActionScript 3.0, it would go like this:
Note that much of the above code is the same in AS3 as it is in AS2. You’ve got
attachNetStream()instead ofattachVideo(), but other than that … well, there is thatlistenerbusiness, but that’s just a failsafe. If your FLV is encoded with metadata (likely, but not guaranteed, depending on how it was encoded), those three lines in the middle ensure that you don’t see a warning in the Compiler Errors panel when you compile. All they do is assign a function to AS3’sNetStream.onMetaDataevent with a dummy (empty) function. The function doesn’t need to do anything, but if it’s absent and the FLV does have metadata, you get the warning.To Kevin …
If you’re using the FLVPlayback Component (sounds like you are), then leave the
sourceparameter empty — you’ll see that in the Parameters tab of the Property inspector (it’s calledsourcein ActionScript 3.0 andcontentPathin ActionScript 2.0) — and make sure the FLVPlayback Component on your Stage has an instance name. At that point, assign an event handler to the FLVPlayback instance — responding to a mouse click, say — that sets thesourceorcontentPathparameter at runtime.You may find that this overrides any built-in buttons — the VCR controls — in your FLVPlayback Component, assuming you’re using an optional skin, so if that’s the case, create a button symbol that has a rectangle only in its Hit frame (this makes the button invisible at runtime). Make that rectangle large enough to fit the visible area of your FLVPlayback Component not counting the VCR controls, and place the button in a layer higher than the Component. Program the button, instead of the FLVPlayback instance, to set the Component’s
sourceorcontentPathparameter. The event handling for the button would be the same as that shown above for the Component.To Elena …
Interesting … I’m not sure why or how the audio could play without the video playing as well. In any case, your own solution should follow along the same vein as my reply to Kevin. The exact syntax will be different (e.g. a
setMedia()method instead of a directcontentPathproperty), but the principle is the same. Keep in mind that any of the selectable parameters of the Component are available via ActionScript as properties by way of its instance name. If may help if you leave the “Automatically Play” parameter off at first, then use ActionScript to set the desired FLV file and, additionally, to play it.August 16th, 2007 at 12:41 pm
Thanks very much for your response, veeery much appreciated! I’ll try that.
August 18th, 2007 at 2:09 pm
I tried the tutorial on “How to Save Bandwidth when Displaying Flash Video” and I’m afraid to say it didn’t work. I hope you don’t take this the wrong way because I do appreciate all that you do, but I did find the tutorial a little hard to follow. I feel like the instructions don’t follow a natural progression like A,B,C, D, but rather go A,B, then to D all of a sudden… which can be off setting if you’re not experienced enough to figure out what C is.
These are the errors I got when I tried to publish the file after completing the tutorial.
1093: Syntax error. videoPlayer.source = “http://hbkitty2.googlepages.com/KeinewieDu_385×220.flv”;
1078: Label must be a simple identifier. videoPlayer.source = “http://hbkitty2.googlepages.com/KeinewieDu_385×220.flv”;
August 19th, 2007 at 8:33 pm
Colin,
Aww, sorry to hear that! The Notes on Design blog has a certain preferred range for number of words and I had already gone over, so that might be part of the problem. In any event, I’ll do my best to clarify here.
That fact that you left a comment about the Notes on Design tutorial on this entry worries me a bit, because the ActionScript in this particular entry is strictly ActionScript 2.0 (your error messages are the ActionScript 3.0 sort) and this one doesn’t deal with the FLVPlayback component except in the Comments section. It’s important to recognize these two approaches to Flash video as distinct, and I mention it just to cover the bases.
The two messages you’ve shown look to me like the result of a single error, not your fault at all. I can’t tell for sure, because WordPress (the software for my blog) often turns straight quotation marks (" … ") into curly quotes (“ … ”) — and that’s my hunch. Make sure you’re quoting the location of your FLV with straight quotes. That should solve it.
August 19th, 2007 at 9:06 pm
Yeah.. I didn’t want the first post to ” Hey this doesn’t work ! ” if you know what I mean.
You mean they give you a limit to the number of words you use even if it means people can’t follow the tutorial. That’s not good.
I used the code from the tutorial. It has the straight quotation marks. I even tried the tutorial once again and it didn’t work. Where you able to get it to work with the CS3 action script ? I don’t see how it could give me an error while working for you other then you might have been testing the flv file locally and not with a http//: address. Do you think that’s the problem ?
August 19th, 2007 at 9:23 pm
Colin,
Heh, no worries, but I appreciate the thought.
They didn’t limit me in any way, but rather, suggested a preferred range, and I went over (and I’m sure I’m not the only one). If the final result of my writing was confusing, the fault lies with me.
I’m looking at their blog again, and I see curly quotes — but I wouldn’t be surprised if the punctuation might render differently in different browsers. In my own testing, both the AS2 and AS3 code worked just fine. It shouldn’t matter whether the FLV is local or on the server, referenced by a relative or absolute path, though you may have problems if the SWF file is on one domain and the FLV file is on another (that wouldn’t show the error messages you’re seeing, though).
August 21st, 2007 at 6:25 pm
I used this method to create a video player with two active NetStream objects (a video and its reflection). Unfortunately, the reflection, or rather, the second NetStream object didn’t appear in Firefox 2.0.0.6. After a little bit of frustration -OK, a LOT of frustration- I deduced that Firefox sets a default max-persistent-connections-to-server in its about:config file.
I was able to change this value (type “about:config” in URL and filter by “http”) however, that doesn’t really solve the issue. My video file works fine on my machine, but I can’t expect other users to change this default value, nor do I understand the greater implications in doing so.
Have you encountered this issue? Do you know of a workaround using the same method? I’ve been reading up on using the AS 3.0 FLVplayback component, but I’ve already written the whole file in AS 2.0 using the NetStream method. I’m hoping not to have to rewrite everything. Suggestions? I simply need to load two of the same video files at the same time and treat them equally.
Thanks for the help in advance -j
August 28th, 2007 at 10:52 am
Jordan,
I’m curious about the situation you’re describing, because if you’re pulling in those FLVs via HTTP — that is, you’re not using Flash Media Server — then those requests are garden variety requests. They would be no different, in principle, from an HTML page that loads dozens of JPGs. In other words, these aren’t persistent connections.
I don’t doubt that your adjustment to Firefox fixed the issue, but that might have just been a fluke. I threw together a quick test case …
… and I’m seeing both videos play, in Firefox and IE.
August 30th, 2007 at 10:52 pm
I am using Flsh8 and was using the FLVplayback component but no video is present when using a web browser to connect to site, however when I open file using ftp client it works fine. I am using a relative path to call the .flv from .swf I tried the
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
videoPlayer.attachVideo(ns);
ns.play(”externalVideo.flv”);
and the same thing, any ideas what i’m doin wrong?
August 31st, 2007 at 7:43 am
Izhar,
In actual practice, you would replace
"externalVideo.flv"with the actual name (and path, if necessary) of your FLV file. Are you doing that? In any case, you don’t need any of theNetConnectionandNetStreamcode if you’re using the FLVPlayback Component, but you do have to let that Component know what video file you intend to play. You can do so without ActionScript at all if you use the Parameters tab of the Property inspector.August 31st, 2007 at 11:33 pm
Hi David Stiller,
Thank you for your reply.
That was elegant. Only problem I can’t get video - only audio to show up. Working with Flash 8 Pro on a windows. Any suggestions?
thanks
Izhar Hussain
September 3rd, 2007 at 9:53 am
Izhar,
That depends on what approach you’re using to get video into your SWF.
If you’re using the approach described in the original blog entry, you will indeed get audio only … unless you correctly configure your Video object. You’ll need to create the Video asset as described in your Library, drag it to the Stage, and give it the instance name referenced in the ActionScript. If you’re using FLVPlayback, it should all work without a hitch as soon as you point the
contentPathparameter to your FLV file. My hunch is that you’re now using the non-FLVPlayback approach, but haven’t given your Video object the instance namevideoPlayer.September 6th, 2007 at 4:53 am
Hi David,
Thank you for your reply.
Ah, yes I got it now. Thanks alot !
Hadn’t quite understood how all this worked, but its running smoothly now!
Thanks alot for your time David!
I hope that you can help me as well…
Izhar Hussain
September 7th, 2007 at 8:40 pm
Hello David - I have read this blog entry with interest because of a problem I am having. Simply, I have created a swf incorporating the FLVPlaback component referencing an external flv that I wish to have play in a html-based cross-platform CDROM. If I use an absolute file path (includng cd drive letter) from the swf to the flv then the flv plays correctly, however if I try to use a relative path then only the controller appears in a blank white box in my html page. This obviously is unacceptable because one does not know what the cd drive letter of the users computer is and also it eliminates Mac users.
Does the above code take care of this problem? I saw you mention somewhere in your responses above that you have been successful in getting flv files to play on a cdrom.
I am desperate for a solution, and after asking for help on several flash discussion forums, nobody has a solution to this problem. Yet I cannot believe that I am the only one who wants to deploy flv on a cdrom.
Thanks in advance.
September 16th, 2007 at 10:18 am
Hi david, I have searched the net for an answer to my question. But I cant find out any help. And I have just came across your blog, I hope you can help
I have created this flash video player that plays only one file. That works fine. But when I load up my XTML page of my site it loads automaticaly. I dont want my video file to load automaticaly.. I want it only to load when the person press’s the play button. Could you point me in the right direction
Im very new to flash! im using action script 2.
My code:
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
ns.setBufferTime(10);
ns.onStatus = function(info) {
if(info.code == “NetStream.Buffer.Full”) {
bufferClip._visible = false;
}
if(info.code == “NetStream.Buffer.Empty”) {
bufferClip._visible = true;
}
if(info.code == “NetStream.Play.Stop”) {
ns.seek(0);
}
}
theVideo.attachVideo(ns);
ns.play(”caroline2.flv”);
rewindButton.onRelease = function() {
ns.seek(0);
}
playButton.onRelease = function() {
ns.pause();
}
var videoInterval = setInterval(videoStatus,100);
var amountLoaded:Number;
var duration:Number;
ns[”onMetaData”] = function(obj) {
duration = obj.duration;
}
function videoStatus() {
amountLoaded = ns.bytesLoaded / ns.bytesTotal;
loader.loadbar._width = amountLoaded * 188.0;
loader.scrub._x = ns.time / duration * 188.0;
}
var scrubInterval;
loader.scrub.onPress = function() {
clearInterval(videoInterval);
scrubInterval = setInterval(scrubit,10);
this.startDrag(false,0,this._y,187, this._y);
}
loader.scrub.onRelease = loader.scrub.onReleaseOutside = function() {
clearInterval(scrubInterval);
videoInterval = setInterval(videoStatus,100);
this.stopDrag();
}
function scrubit() {
ns.seek(Math.floor(loader.scrub._x/187*duration));
}
var theMenu:ContextMenu = new ContextMenu();
theMenu.hideBuiltInItems();
_root.menu = theMenu;
var i1:ContextMenuItem = new ContextMenuItem(”:::: Video Controls :::::”,trace);
theMenu.customItems[0] = i1;
var i2:ContextMenuItem = new ContextMenuItem(”Play / Pause Video”,pauseIt,true);
theMenu.customItems[1] = i2;
var i3:ContextMenuItem = new ContextMenuItem(”Replay Video”,replayIt);
theMenu.customItems[2] = i3;
var i4:ContextMenuItem = new ContextMenuItem(”Copyright 2007″,trace,true);
theMenu.customItems[3] = i4;
function pauseIt() {
ns.pause();
}
function replayIt() {
ns.seek(0);
}
_root.createEmptyMovieClip(”Vsound”,_root.getNextHighestDepth())
vSound.attachAudio(ns);
var so:Sound = new Sound (vSound);
so.setVolume(100);
mute.onRollOver = function() {
if(so.getVolume() == 100) {
this.gotoAndStop(”onOver”);
}
else {this.gotoAndStop(”MuteOver”);
}
}
mute.onRollOut = function() {
if(so.getVolume() == 100) {
this.gotoAndStop(”on”);
}
else {this.gotoAndStop(”Mute”);
}
}
mute.onRelease = function() {
if(so.getVolume() == 100) {
so.setVolume(0);
this.gotoAndStop(”muteOver”);
}
else {
so.setVolume(100);
this.gotoAndStop(”onOver”);
}
}
September 17th, 2007 at 4:53 pm
Hi David,
My issue is also the audio only plays, but the real issue is that my content path is across domains. Meaning, the flv is on 1 server and the swf container file is on another. Will this matter?
September 18th, 2007 at 8:39 am
To Izhar …
You’re welcome! Good luck as you continue to learn. I can tell you first hand, the learning never stops.
To Brian …
I believe it — and that sense of desparation is one of my least favorite aspects of development (if not the least favorite). In light of your anxiety, I feel badly for responding so late! I’ve had an intense month myself due to a couple out of town trips.
Brian, I wonder if what you’re seeing is possibly related to something I recounted in “(Perhaps) Unexpected Points of View: SWF Defers to HTML”? That’s a thought, anyway. In the very least, you should start to use a few debugging techniques, such as
trace()or the Debugger panel, to start peeking under the hood of your SWF. Because your SWFs are running in a browser, you may want to use remote debugging, as described here:http://www.adobe.com/devnet/flash/articles/debugging_actionscript.html
To Matthew …
The reason your video plays immediately is because of this line here:
ns.play("caroline2.flv");… so you’ll need to get rid of that. If the
NetStreaminstance doesn’t know the location of your FLV file, it can’t start loading it.Instead, change your Play button’s behavior from what it is —
ns.pause();— tons.play("caroline2.flv");. Makes sense so far, right?Only problem is, you also want that button to invoke
NetStream.pause();. Seems like, ultimately, you’ll want the Play button to invokeplay()first, thenpause()later, and I can already see one way to check for that. TheNetStream.timeproperty tells you how far along the video has played. So how about something like this:Note that I supplied the optional parameter to
NetStream.pause(), to ensure that the method does what you expect (it is a toggle, after all, without the parameter, and therefore doesn’t necessarily mean “pause”). You’ll probably want to use that same optional parameter in your Pause button’s event handler (specifyingtrueinstead).To Anthony …
Different domains will indeed make a difference. The security sandbox has changed (becomming more strict) with each new release of Flash Player for a couple versions now. It’s entirely possible to serve up content from one domain and consume it in a SWF from another, but you have to take the necessary measures.
Flash Player 9 Security white paper
Flash Player 8 Security white paper
That said, I would start small and make sure you get the video to run properly first without the added complexity of cross domain issues.
September 18th, 2007 at 8:38 pm
Hi David,
After reading through all these posts I worked up the code you see below. the good news is that it works. For those looking to do the same, which is to load an external FLV for a kiosk type app, this will load a FLV from a local resource, position it, and play ( looping ).
My problem, is that I need to be able to replace the playing flv, with another Flv. I can’t seem to get the name of the instance created, to kill it and then spawn a new net connection to the next clip I need (this is for a card game, all files are rendered flv’s). It seems the instance name changes so I am having trouble moving to the next step (remove current FLV at the pixel location, and load a new one).
Perhaps I am way off the mark and should somehow encapsulate into a movie clip? That seems a bit antiquated but maybe not.
Target deployment is CS3, AS3, on a standalone terminal.
Any light you can shed on how to kill, unload this loaded FLV so I can start a new one up? I searched long and hard but have yet to find a nugget of information to springboard off of again. Your posts in this thread is what got me to where I am today, thanks so much.
- Scott (smic)
function setupDealer1():void {
var videoPath = new String();
videoPath = “theme/p1_join_01.flv”;
trace(”position 1, DealerScreen videoPath is” + videoPath);
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
var vid1:Video = new Video();
this.addChild(vid1);
vid1.x = 40.8
vid1.y = 230
vid1.width = 207
vid1.height = 467
vid1.attachNetStream(ns);
ns.play(videoPath);
ns.addEventListener(NetStatusEvent.NET_STATUS, statusHandler);
function statusHandler(event:NetStatusEvent):void {
// trace(event.info.code);
switch (event.info.code) {
case “NetStream.Play.Start” :
trace(”Start [” + ns.time.toFixed(3) + ” seconds]”);
break;
case “NetStream.Play.Stop” :
trace(”Stop [” + ns.time.toFixed(3) + ” seconds]”);
ns.play(videoPath);
break;
}
}
var netClient:Object = new Object();
netClient.onMetaData = function(meta:Object)
{
// trace(meta.duration);
};
ns.client = netClient;
}
September 18th, 2007 at 8:39 pm
and I am sorry, should have posted this to the non component post.
September 20th, 2007 at 10:19 am
Thanks for your help david. I will put your wise words to good use. Im very new to flash! I hope to one day be as good as you
Keep up the good work
Kind regards
Matthew
September 25th, 2007 at 3:35 pm
Hi David,
I’m a NOVICE to Flash Video. I purchased Flash Video Pro 8 to encode videos online.
I have encoded my first flash video online at http://resume.djcarl.com, however, the FLVPlayback component .swf controller is “not publishing with the video”.
I have used the SteelOverAll.swf controller and as you can see from the link above, it does not display online.
What can I do to fix this step-by-step? I would like my controller to publish with the video online.
Thank you,
Carl
Orlando, Florida
September 26th, 2007 at 8:54 am
To Scott …
ActionScript 3.0 is different from ActionScript 2.0 in a number of important ways, so I’m glad this blog entry was able to help you to this point.
When I read this part …
… a couple things come to mind. First, I notice you’ve wrapped most of your code inside a custom
setupDealer1()function. Nothing wrong with that, per se, but you should be aware that declaring your variables inside thesetupDealer1()function scopes them to that function. If you attempt to reference, say, yourvid1instance in later code, you’ll find that it doesn’t exist. In order to make your various instances —vid1,ns, etc. — more globally accessible, declare them outside the function, then use the function itself to refer to those variables and use them in whatever way makes sense.My other thought was triggered by your phrase “spawn a new net connection,” which suggests to me that you may believe you need a new
NetConnectioninstance every time you want a new video (along with, perhaps, a newNetStreaminstance, and so on). In case that’s what you meant, you’ll be happy to hear that you only need one instance of the related classes apiece and can re-use them as often as you like.You shouldn’t have to kill the existing FLV, but rather, invoke that
NetStream.play()method as desired with a new file path.To Matthew …
Thanks for that! I’m always glad to hear it when these articles are helpful.
To Carl …
The SteelOverAll skin — in fact, all of the FLVPlayback skins — are actual separate SWF files that must be uploaded to the server in addition to the FLV and the SWF that houses the FLVPlayback component. These files must all be in the same relative location to each other on the server as they are locally. The first step is to ascertain that your skin has been uploaded. If so, something else has gone awry and I’ll try to help you through that.
September 28th, 2007 at 3:10 pm
Yes, I have uploaded the SteelOverAll.swf skin to the same exact folder on the server as the .fla, .flv and .swf (4 files total). If you look at http://resume.djcarl.com, then you will see a space below the video.
The video is 320×240
The controller is “Over the Video”
The stage setting is 320×240
There is a space below the video…
This space is there with the “external controller.swf” and the “over the video controller.swf”. In both scenarios, when I tested it locally, I saw the controllers and “the space”. When I uploaded it to the server, I didn’t see the controllers, but had that “the space” publish…
Hope you can help…
September 28th, 2007 at 6:59 pm
Carl,
Aha, this looks like a security sandbox issue. I used my browser to view source on your resume page. That showed me that your Universal.swf file is located here …
djcarl.com/_flash/
… which Flash Player considers a different domain from this …
resume.djcarl.com/
… simply because of the addition of the subdomain resume. Flash Player is okay with loading Universal.swf itself, but Unversal.swf in turn requests another SWF file (SteelOverAll.swf) that appears to be hosted on another domain, and that’s too dicey for recent versions of Flash Player. (Note that if you reference the SWF directly —
http://djcarl.com/_flash/Universal.swf
— the controls load, because from this point of fiew, Unversal.swf is loading “safe” content from the same domain.)
The quickest fix, if you can arrange it, is to reference Universal.swf from the same domain (in this strict definition of “same”) as the HTML page that loads it. In other words, in your HTML, change this …
http://djcarl.com/_flash/Universal.swf
… to this …
http://resume.djcarl.com/_flash/Universal.swf
If you can’t do that, you’ll have to put a cross domain policy file on the machine that hosts djcarl.com (the one without the resume subdomain).
September 29th, 2007 at 5:06 pm
David,
I have taken your advice. Thank you! I told you that I’m a NOVICE. I’m without success. Here is what I did:
I took the four files (SteelOverAll.swf, Universal.swf, Universal.fla and Universal.flv) from the www.djcarl.com/_flash folder and moved them to the subdomain resume folder.
Within the resume folder, we have the four (4) files and the index page (1). Five files total.
I have also added the crossdomain.xml to the djcarl.com root directory
The code on resume.djcarl.com now references
http://resume.djcarl.com/Universal.swf and still the same result… (Take a look)
Also, those same 4 files “are still” in the (a) www.djcarl.com/_flash/ folder. They are in the (b) resume subdomain folder and I have them in the (c) root directory of djcarl.com with the crossdomain.xml file
I’m wondering if my Flash video set-up was incorrect because when I tested the page locally, I saw the controller with the video, however, I saw that space below the video too?
Could it be that the space below the video may be the cause to “SteelOverAll.swf” and “SteelExternalAll.swf” controllers not publishing?
Maybe I need a step-by-step in the Encoding Video process?
Thanks,
Carl
September 29th, 2007 at 5:25 pm
Sorry David! It worked once I uploaded it real-time! Nice!
How can I get rid of that space below the video in the set-process?
Thanks!!!
Carl
September 29th, 2007 at 7:25 pm
Carl,
Ah, glad to hear that! The key was the subdomains, then, so file that factoid away for future reference.
As for the space below … under the current circumstances, you’ve embedded a SWF that’s 206 pixels high and put it into a space that’s 240 pixels tall, so the height of the SWF is what it is. If you choose one of the “Under” skins (rather than SteelExternalAll.swf, for example) you’ll find that the controller moves beneath the area that displays the video content. That may just fill that space perfectly.
October 1st, 2007 at 2:22 pm
Thank you David! I’m glad I found your blog! You helped me out big time!!! I communicated my issue to many people and you were the only one to come through to solve this specific issue with the controller. Take care!!!
Carl
Orlando, Florida
October 2nd, 2007 at 1:04 pm
Carl,
Nice!
October 2nd, 2007 at 6:51 pm
David,
Thanks…that solved it. with the changes suggested I can now do movie replacements with ease. I did add more code to change the x,y, height and width on the fly as they are loaded in, and I am back on track.
Thanks again.
October 9th, 2007 at 10:05 am
Scott,
Glad to hear it.
October 12th, 2007 at 4:07 pm
David,
Hopefully this one hasn’t been asked yet; if so, please reference the answer.
I’m currently doing Flash 9 / AS3 / FMS2 development at work. I have a working example of video playback (using AS2 and the Video class) that I have live right now (www.daihen-usa.com/kazuo/DAIHEN_mp.swf). Videos seem to be streaming just fine via the standard rtmp protocol for FMS2, which is running on our server. Everything uses the standard AS2 NetStream and NetConnection framework.
However, I’m looking to move this into the FLVPlayback component and can’t figure out how to play them. My understanding this would all be done through the source parameter of my FLVPlayback component — i.e.,
video_player.source = (path to video). Only I can’t figure out what the path should be!
Or am I just looking at this the wrong way?
Many thanks in advance for any help you can provide on this subject.
October 13th, 2007 at 6:48 pm
Alex,
In ActionScript 3.0, you’re right, it’s the
FLVPlayback.sourceproperty you’re after. Now, you mentioned that in the AS2 world, you had this working just fine with theNetStreamapproach, so you must have had a set of RTMP addresses handy, right? When you typed thatNetStream.play()method, you provided an RTMP path as your parameter — it’s that same path you’ll need to supply tosource.October 17th, 2007 at 1:28 pm
Dave,
It should be noted that my working example is closely based off an example from adobe.com’s dev center for the Flash Media Server 2. I can’t recall if this was one of the included examples that came with FMS2, but it’s fairly straightforward - I just went back in and gave it a little customization.
That said, the working AS2 / Flash 8 example I have works by connecting the client net connection (called client_nc) to the rtmp url (saved as a string). Then, when a video item in the list is clicked, a listener set up on the list processes the video request by using an event object as its source. Essentially, the contents of this object is the string literal of the file name - which is what is displayed in the list. At the point, the video net stream is set to play the targeted video:
video_ns.play(eventObject.target.value); // parameter is simply the name
of the flv file, less the “.flv” extention at the end.
Finally, the video is played on the Video object using the following line:
Replay_Video.attachVideo(video_ns);
In other words, to answer your question if I had a set of RTMP addresses handy, the answer is, “I’m not sure.” The system works but I’m not entirely sure what the full addresses are for the videos that stream.
This is where I get all confused, for a few different reasons.
1. At no point during this program does anything make an explicit call to the FMS2 in the lines
(player).source = “rtmp://[my_server]/[some_file].flv
I have tried doing this explicitly but to no avail.
2. Do I need to set up a net stream and net connection for this to work? Or is this somehow “built-in” to the new FLVplayer component?
3. Are there any working examples of this?
Thanks again for any help you can provide on this.
October 30th, 2007 at 10:17 pm
Great tutorial!!! Just what I was looking for. One more thing, how can I have it so the swf just sits there on the page until clicked. Upon clicking, it would play the flv.
Thanks.
November 1st, 2007 at 3:00 pm
Kamil,
For something like that, you could omit the
ns.play("externalVideo.flv");line so that it could be triggered in response to the click. If you had a button somewhere, you could assign a function to theButton.onReleaseevent like so:If you didn’t have a button or movie clip handy, you could trigger that line with a
Mouse.onMouseUpevent handler:November 7th, 2007 at 5:03 pm
Wow, I must say I am glad you still update this article! I want to thank you for the information. I haven’t found anything like it… I am having a problem though. This is the first time I am trying to use video without the component… so like Markus back in 06 stated… (although he wanted to use a component, I think… I just want the video to ’steam’ without controlling it at all… its a background video.
I can only hear the test video, not actually see it (the actual video has no sound)…
plus, I have embedded cue points in the flv and was wondering if you could send me down the right path with those… I just want to have the actionscript add a movie clip to the root each time the cue point is triggered.
Thanks!!
November 7th, 2007 at 5:33 pm
Lauren,
I think this is the single most popular article on the blog, so it generates a lot of comments.
I’m always happy to keep stuff fresh, and very soon now, I plan to write ActionScript 3.0 versions of the most frequently visited articles here.
Markus did manage to get his issue resolved — the audio-but-no-video issue, at any rate — and I think, at the time, he was confusing components with the Video object this approach requires. Did you drag a copy of the Video object to the Stage yet (you’ll need to create it in the Library first)? Does that Video object have an instance name (see the Property inspector when you have the object selected), and is that the instance name you’re using in front of the
attachVideo(ns);line?My “How to Use Flash Video (FLV) Cue Points” article should give you a good head start on video cue points, but don’t hesitate to add questions to that one if you need additional help.
November 7th, 2007 at 5:52 pm
Awesome — I am well.. I have been looking at this code way too long… I spelled video incorrectly… thank you for picking up my slack…
As for the article… i am getting a 404 error and I searched for it on your site and I can’t seem to find it.
I know this would be pretty simple minded of me… but can I just trace(cuePoints) ? Or something to that effect?
I simply want something.cuePoint = function () {
attachMovie(”plus1″,”plus”, 100)
} and each cuepoint would attach the same movieclip…
Thanks… I really appreciate your speedyness! You respond faster than my professor can even get over to my station!
THANKS!
November 7th, 2007 at 8:16 pm
Lauren,
Wow, that’s odd. I republished that cue points article and it seems to be showing now (for other friends on other networks, too). Must have been something wrong with WordPress that day (thanks for picking up myslack!).
Ha! Luck of the draw, that. Let me know if you still can’t see the cue points article. That should help you see how to trace what you’re after.
November 8th, 2007 at 1:04 pm
Hi David,
You have helped me before and I truly appreciate your response time and KNOWLEDGE!!!
I have 2 questions:
1. How does one set-up Flash Videos with Flash Pro 8 that shows the time length of the video like youtube.com does with its videos?
2. Where can I learn EASY “step-by-step” how to set-up a Flash video player like the one on yahoo, i.e., http://cosmos.bcst.yahoo.com/up/player/popup/?rn=3906861&cl=4927532&ch=4226715&src=news
Thank you!
Carl
Orlando, Florida
November 11th, 2007 at 2:44 pm
Thanks for this tutorial. How would you go about adding multiple videos? I created a key frame for each Video and each carries a key frame with it’s own AS. I changed the Instance name for each but only one of them works. Any idea how to add multiple videos?
November 13th, 2007 at 11:58 am
To Carl …
The version of Flash, per se, isn’t as important to the solution as the version of ActionScript you’ll be using. This particular blog entry was written for ActionScript 2.0, which is ideal for Flash 8 or Flash MX 2004. (Flash CS3 would also allow you to use AS2, but you could alternatively use AS3.)
Since you’ll be using AS2, you may actually be able to figure out quite a bit from the other AS2-based articles on this site. “How to Build a Flash Video (FLV) Progress Bar,” for example, shows how to extract and use length/duration values from your FLVs, and you’ll find plenty more simply by searching the word “video” in the search field of the blog’s main page.
To be frankly honest — and at the same time friendly, if frank can be friendly
— I think that an easy, step-by-step guide to building a Yahoo!-style video player would have to be a very long document indeed. The key to achieving such a goal, at least in programming, is to break down the ultimate endeavor into as many sub-parts as needed, mastering each small part as you go.
A big help, along those lines, is to consider your various parts as the objects they are, and to understand that objects are defined by classes, which define their properties (characteristics), methods (things they can do), and events (things they can react to). In terms of Flash video — if you’re not using FLVPlayback — your main classes of interest will be
NetStreamandVideo.To Tony …
All you need is one instance apiece of the classes shown:
NetConnection,NetStream, andVideo. If you let your Video object stretch across all those frames, you should be fine. As long as the Video object is associated with itsNetStreaninstance at the beginning of your span of frames, you’re good to go. To change what video is shown, you’ll simply invokeNetStream.play()on yourNetStreaminstance (here,ns) and specify the name of a new FLV file. And if you like, you don’t even need all the extra frames. By using buttons or maybe detecting the completion of each FLV, you can play new videos as often as you like — all from the same single timeline frame.November 13th, 2007 at 11:23 pm
Thanks David!
Do you have a book out? You should. You’re very good!
November 14th, 2007 at 10:05 am
Carl,
Thanks! As a matter of fact, I just had my first book published a few months ago.
I co-authored Foundation Flash CS3 for Designers (friends of ED) with a good friend of mine, Tom Green. and wrote the interactivity chapter for How to Cheat in Adobe Flash CS3 (Focal Press), written by another good friend of mine, Chris Georgenes.
November 15th, 2007 at 1:27 am
Hi David,
I have a small problem. I m playing flv file from webserver. The thing is I want to get status from flash saying that NetStream has finished playing the flv file. I trace NetStream.onStatus. There i get NetStream.Play.Stop flag once playing is finished. But the problem is if I click play button again the trace doesnt show NetStream.onStatus in the output.
The code goes as follows: -
var duration:Number = 0;
var ratio:Number = 0;
var idTracking:Number = 0;
var idLoading:Number = 0;
_global.ns1.onMetaData = function(infoObject:Object):Void {
duration = infoObject.duration;
ratio = tracker._width / duration;
idTracking = setInterval(updateKnob, 50);
idLoading = setInterval(updateLoader, 50);
for (prop:String in infoObject) {
trace(prop + “: ” + infoObject[prop]);
}
}
_global.ns1.onStatus = function(infoObject:Object) {
trace(”ns1.onStatus called: (”+getTimer()+” ms)”);
for (var prop in infoObject) {
trace(”\t”+prop+”:\t”+infoObject[prop]);
if(infoObject[prop] == “NetStream.Buffer.Full”)
{
startWatchStream1();
}else if(infoObject[prop] == “NetStream.Buffer.Full”)
{
stopWatchStream1();
}
if(infoObject[prop] == “NetStream.Play.Stop”) {
stopWatchStream1();
}
}
trace(”");
if (this.time > 0 && this.time >= (duration - 0.5)) {
clearInterval(idTracking);
delete this.onStatus;
}
}
_global.ns1.onPlayStatus = function(infoObject:Object) {
trace(”NetStream.onPlayStatus called: (”+getTimer()+” ms)”);
for (var prop in infoObject) {
trace(”\t”+prop+”:\t”+infoObject[prop]);
}
}
startWatchStream1 = function():Void {
delete this.onEnterFrame;
this.onEnterFrame = function()
{
tplayerstatus = _global.ns1.time;
if(ns1.time == duration) {
trace(”!”+duration);
stopWatchStream1();
}
}
}
stopWatchStream1 = function():Void {
playButton._visible = true;
stopButton._visible = false;
playButton.enabled = true;
stopButton.enabled = false;
ratio = 0;
updateKnob();
tplayerstatus = “”;
delete this.onEnterFrame;
}
my_video.attachAudio(_global.ns1);
function updateKnob():Void {
knob._x = tracker._x + _global.ns1.time * ratio;
}
knob.onPress = function():Void {
clearInterval(idTracking);
_global.ns1.pause(true);
this.onMouseMove = function():Void {
if (tracker._xmouse > 0 && tracker._xmouse = 98) {
loader._xscale = 100;
clearInterval(idLoading);
}
}
tracker.onRelease = function():Void {
if (this._xmouse > 0 && this._xmouse
November 15th, 2007 at 2:12 am
Continuing to the previous post.. I hv put following code for the play Button
on(release) {
var filename = _global.flvpath+_global.lastsound+”.flv”;
playButton._visible = false;
stopButton._visible = true;
playButton.enabled = false;
stopButton.enabled = true;
_global.ns1.play(filename);
startWatchStream1()’
}
November 19th, 2007 at 1:56 pm
Do I need to have Flash Media Server installed to get this to work? I loaded my files onto 2 different servers. The server that has FMS works properly while the other one doesn’t. If my contentPath directs to the server with FMS, only then will it work.
November 19th, 2007 at 2:11 pm
Scott,
You mention
contentPath, so it sounds like you’re using the FLVPlayback component. The approach described in this blog entry is specifically geared toward not using FLVPlayback — not that there’s anything wrong with the component … it’s just that the code shown above isn’t intended for FLVPlayback use. Either which way, though, FLVs do not necessarily need Flash Media Server.November 20th, 2007 at 8:47 pm
ace,
Woops! Sorry I missed your comment just before Scott’s.
Wow, that was a lot of code! Unfortunately, it looks like some of it was even cut off. You had one question — why isn’t
onStatusdispatched when the video is played? — and for better or worse … honestly, I’m just looking at too much here to give you a useful answer. To make matters worse, even if I copied and pasted your code into a FLA, that still wouldn’t be enough, because part of it is missing — plus, I don’t know how your assets were arranged in the file. I do see you’re handling anonPlayStatusevent, which isn’t supported in AS2 (that’s an AS3NetStreammember), so maybe that’s the issue?When I run into unexpected behavior in my scripts, the first thing I do is try to isolate the issue into small chunks until I can better see what’s going on. For something like this, I would save my work, start a new FLA, and write up a new throw-away
NetStream.onStatushandler and test it like mad. Trace out starting and stopping, all without the extra baggage of the original code. If what I see makes sense, I start bringing in chunks of the other file section by section (sometimes line by line). It’s work, for sure, it in my experience, it leads to the answer every single time.November 20th, 2007 at 9:52 pm
[Follow up on Alex Baker, several posts back …]
Alex and I corresponded briefly via email and managed to make a bit of progress with his issue.
November 24th, 2007 at 8:21 pm
Hi David,
I can’t believe I just read through this entire blog but I’m very impressed! I’m a total novice (untrained) and only recently began using Flash MX 2004 to update my site which was completely built on Flash (by someone else). I used your original script as is and it works like a charm locally on my PC but not through my server. I initially thought I may have the same problem above as someone who needed MIME types from his web Host, but the technical support at my Host said the MIME is already present and had no explanation or advice as to why the video doesn’t play on my site. I can confirm that all the related files (the html, the .swf and the .fla) are located in the same directory, just as when on my pc. I’ve given the video ages of time to load to see if its related to the size of the video, but it just never plays. Is there anything you think I should try? Below is my coding.
The SWF associated with the coding is called: “VideoStreamTest2.swf” and is loaded by a Button having the following script:
on (release) {
loadMovieNum(”VideoStreamTest2.swf”, 2);
}
And this is the coding for “VideoStreamTest2.swf”
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
videoPlayer.attachVideo(ns);
ns.play(”ThePhilippines_Draft11.FLV”);
Thanks in Advance!
Kurt
November 27th, 2007 at 12:45 am
Kurt,
Wow! That’s a lot to read! Thanks for the kind words.
Interesting. Well, you covered two questions I would have asked (the MIME setting and file locations on the server). Your best bet at this point is to break down the complexity just a bit. You’ve got two things going on: a) loading a SWF and b) loading an FLV. What happens if you test VideoStreamTest2.swf just on its own — both on your PC and on the server?
January 7th, 2008 at 11:32 pm
thanks for your help last time. here is another one! how to load flv randomly?
January 8th, 2008 at 4:48 pm
David,
Great site. Hope you can help me.
Like Brad of July 24, 2007, I’m trying to to play an FLV file and once it ends have it go to another scene. But I don’t want to use a button to have it go to the other scene (in my project I want to FLV file to play - it’s in scene 2, and then go back to scene 1). I would like the FLV file to automatically go back to scene 1 once it is complete.
Also like Brad I’m more of a designer than programmer. So any help you can provide me with this problem is sincerely appreciated.
Thanks in advance,
Robert
January 8th, 2008 at 9:50 pm
hi david,
i am putting my question a bit into details. could u tell me the script to load my flv randomly on the main page of my “papajaypictures”? it is really impressed your help last time when i didn’t even know how to load flv! thanks!!
January 13th, 2008 at 1:26 pm
To beryl …
There are a number of ways I can think of to interpret your question, so it may help me to get a bit more information on what you’re after. If you have a small list of FLV files, you could certainly store them in an
Arrayinstance (an array is essentially just a list), then pick an element from that array usingMath.random(). Check it out:That would cause a file name to be chosen at random from the arbitrarily named
videosarray. Every time someone refreshed the page, a different video would play. Add as many file names to that array as you please. The random selection takes its cue from theArray.lengthproperty of thevideosarray.Math.random()returns a number between zero and one (actually, greater than or equal to zero and less than one). In turn, that value is multiplied by the number of elements in the array, which is then rounded down to the nearest integer byMath.floor(). Finally, the result is fed into thevideosarray to retrieve one of its elements.To Robert …
Instead of responding to a button click, you can instead respond to the end of the video itself. In either case, you’re handling an event, it’s just that the event changes. If you’re working in ActionScript 2.0, check out “How to Determine the Completion of a Flash Video (FLV) File” and let me know if that makes sense to you. Instead of the
If you’re using ActionScript 3.0, the syntax will be slightly different, so either way, let me know if you get stuck.
trace("Video complete");line of that example, you can usegotoAndPlay()or any other instruction you like.January 23rd, 2008 at 11:29 am
Thanks David for your insight into my problem. Seems though I only have things partially worked out.
After taking your advice I created this script:
var listener:Object = new Object();
listener.complete = function(evt:Object):Void {
gotoAndPlay(”Scene 1″, 5);
trace(evt.state);
trace(evt.playheadTime);
}
videoPlayer.addEventListener(”complete”, listener);
//
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
ns.setBufferTime(2);
// Loop code goes here
ns.onStatus = function(info) {
if (info.code == “NetStream.Play.Stop”) {
ns.seek(0);
}
};
myVideo.attachVideo(ns);
ns.play(”culturalCenters.flv”);
It works perfectly! It does everything I want it to do. So, after copying and pasting it for a couple of my other scenes, I applied it to those scenes. Below is an example from one of those scenes:
var listener:Object = new Object();
listener.complete = function(evt:Object):Void {
gotoAndPlay(”Scene 1″, 5);
trace(evt.state);
trace(evt.playheadTime);
}
videoPlayer.addEventListener(”complete”, listener);
//
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
ns.setBufferTime(2);
// Loop code goes here
ns.onStatus = function(info) {
if (info.code == “NetStream.Play.Stop”) {
ns.seek(0);
}
};
programVideo.attachVideo(ns);
ns.play(”programs.flv”);
The only difference with this script and the previous one is, of course, I using a different .flv file and I named my “name”.attachVideo(ns) script differently. Although when I first tried this I just kept the “name”.attachVideo(ns) script the same as the original.
But regardless, this script does not work at all. It seems that when the .flv finishes playing it doesn’t go back to Scene 1, Frame 5 like I want it to. But rather it either goes to the “Cultural Center” video like the original script does, or it will go to a preceding video, even though, again, the script has the “gotoAndPlay” script that tells it to go to Scene 1, Frame 5.
I’m at a lost as to what I’m doing wrong. Please help if you can.
Thanks in advance.
Robert
January 23rd, 2008 at 8:32 pm
Robert,
You’re using two different approaches in determining the end of your video: a) the
listener(Object) approach and b) aNetStream.onStatusevent handler that checks forNetStream.Play.Stop. Of those, thelistenerapproach works in conjunction with the FLVPlayback component, and the other works with theNetStreamclass (that is, no FLVPlayback component), so I’m not sure what mechanism you’re using to play your FLVs.You said the first of your script blocks works, so that suggests to me that you’re using the FLVPlayback component, because the
gotoAndPlay()inside thecompletehandler sounds as if it succeeds. If that’s so, youronStatushandler may not be doing anything useful at all — again, because that approach isn’t supposed to be used with FLVPlayback.That “name” you’re talking about needs to match the instance name you’ve given to your Video object, otherwise ActionScript isn’t speaking meaningfully to an object in that line. If you’re using the FLVPlayback component, you’ll need to give it an instance name using the Property inspector — and you’ll need to stick with
FLVPlayback-specific properties, methods, and events. If you’re using a Video object, you’ll need to give itNetStream-specific properties, methods, and events.Does that make sense? It think you’re close, but it sounds like you’re (maybe?) confusing or combining more than one approach. In cases like this, if often helps tremendously to simplify the scenario. Save your work, start a brand new FLA file, then take small steps toward the goal(s) you have in mind, making sure you understand exactly what’s going on from step to step.
January 24th, 2008 at 6:00 pm
As a follow-up to my last message:
Following your information I created this script:
var duration:Number = 0;
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
myVideo.attachVideo(ns);
ns.play(”templinMessage.flv”);
ns.onMetaData = function(evt:Object):Void {
duration = evt.duration;
};
ns.onStatus = function(evt:Object):Void {
if (this.time > 0 && this.time >= duration) {
gotoAndPlay(”Scene 1″, 1);
delete this.onStatus;
}
}
Unfortunately, it doesn’t work. Although in playing around with it, I did manage to get the movie to stop playing as I scripted it to. But when I tried to make it to go to the scene I wanted using the “gotoAndPlay” script, it didn’t want to work.
I feel I’m close, but insufficient programming skills on my part prevents me from figuring this out.
Again, your help needed and appreciated.
Robert
January 27th, 2008 at 10:02 pm
Robert,
Check out my reply to one of your other posts (just after my comments to Kate). That should do it — but write back if you’re still stuck.
February 19th, 2008 at 9:06 am
Check my site I’m working on doing one page for all of my videos i just need to load the videos into one player and I'’m stuck with the script Its all in one folder the videos and the file with the player I need a simple> on press >load movie “life.flv” type script please help?
February 19th, 2008 at 3:05 pm
Hello! I used to implement this using an Flash AS3 document class (package) but see strange problem. When I test movie Standalone it works great even if works via AMFPHP which is at remote server and files are remote. BUT. When I put code into webpage which is at the same server as AMFPHP, it halts right after class variables init and issues no error messages. After I click it starts work. Looks like it was with IE6 and FlashPlayer 8 when you needed to “click to activate”. But that’s not that case. It also in mozilla. I do not know what to do. Is there any workaround on that issue?
February 27th, 2008 at 11:21 am
I am experiencing a weird issue. I added video playback to my flash movie to play before a large loading process takes place. I was hoping it would talk to the user while stuff is loading in the background. What happens is that it plays the first couple seconds of the movie, pauses everything while the other stuff loads, then continues the movie with the other stuff already loaded.
Anyway to separate the threads in flash?
March 17th, 2008 at 8:58 pm
To Randall …
I’m unusually behind in my blog replies, so I’m not sure my response will still be useful to you — I hope so! but it’s been so long … — to get a button to load your video, you could give your button symbol an instance name (let’s say
myButton) and then:I’m not sure how this relates to a folder full of videos, though. Did you want the button click to progress from one video to the next? In other words, first click plays first video, second click plays second, third plays third, and so on? If so, you could put all your videos into an array and do something like this:
To Egeshi …
The syntax is a little bit different in AS3, so I hope you used actual AS3 code in your document class. The Internet Explorer “click to activate” issue wasn’t just a Flash 8 problem, but rather a problem for all Active Content, including all versions of Flash Player, QuickTime, Java applets, and so on. Are you sure this isn’t the “click to activate” issue?
To Ronnie …
Flash isn’t multithreaded, so any sort of multithreading desired has to be faked with complex timers. I’ve heard/read about hacks like that, but haven’t every tried it. I wouldn’t think your download should choked out the video, but I’m afraid I haven’t tried that either. Sorry I couldn’t be a help on this one!
March 26th, 2008 at 11:38 am
“the FLV files will not run when the application (which is an EXE) is run over a UNC path”
Brian Says:
May 11th, 2007 at 11:37 am
Jeff: I was having this same problem. It’s actually really simple to solve. You have to set the “autoplay” parameter to false. And that’s it.
After your flv is positioned on your stage, select it. In the properties window, there is a tab for parameters, under parameters you’ll see the auto play set to true. Change it to false.
JEFF, YOU SOLUTION DONT WORK… PROJECTOR DONT LOAD FLV MOVIES WITH RELATIVE PATHS. THAT SUCKS.
March 27th, 2008 at 3:31 am
hi
i hav a flv player, inside a html page,
in html page one button is there,
that button should be invisible until user click & watch half of the flv movie(suppose it reach to a particular cue point),
after reaching particular cue point,that html button should be automatically active,
any idea how to do this type of thing using javascript in flash,plz provide the code for that
April 2nd, 2008 at 11:56 am
neeraj,
I replied to your question in the cue points blog entry.
April 3rd, 2008 at 3:46 pm
Thank you so much for your useful tips and advice. I used AS2 to build a nice video player using your code. So thanks again.
But now I’m having a real problem in AS3 with flv video. I have a main movie, on whose menu are two buttons, one called “music” and the other called “films”, used to navigate to their respective sections of the site. Each button loads an external swf. The “films” swf consists of two movie clips which have streaming flv videos. These streaming videos are made possible in the usual way, by creating a video holder object, a NetStream object, and attaching them. Blah Blah.
Here’s the infuriating part: when I then click the “music” button in the main menu to navigate to that section of the site, Flash loads the external “music” swf into the same loader object as the “films” swf, and everything from the “films” swf goes away, EXCEPT for the effing video stream! It just floats there in the background. It stops playing, but I can’t get it to GO AWAY no matter what I do.
I’ve tried accessing the external “films” swf from the main menu buttons and trying to somehow get them to wipe off the video container, but it just doesn’t work. I’ve tried loading the video container for the films into the main timeline, but that doesn’t work, because the externally loaded swfs can’t find the video container. I’ve even tried making the “films” section into a hidden movie clip within the main timeline. AARGH!
Just talking about it makes me want to tear my hear out. Do you have any idea how I might fix this problem? I really would love some help.
Thank you so much!
Truly,
Michael J
April 4th, 2008 at 8:18 pm
Michael,
My first inclination is to reference the
NetStreaminstance inside the loaded SWF file and invokeNetStream.close()on it before loading something else with the sameLoaderinstance. It sounds like you’ve already tried something like that, but have you noodled around — say, withtrace()— to make sure you’re actually connecting with the desiredNetStreaminstance?April 24th, 2008 at 1:02 pm
is it possible to do something like so PLAYER_NAME.source = FlashVars?
April 24th, 2008 at 2:10 pm
Morgan,
There is.
Since you mentioned “source,” my hunch is that you’re referring to the
FLVPlayback.sourceproperty, which is ActionScript 3.0. If that’s it, just set yoursourceto the expressionroot.loaderInfo.parameters.videoSource, wherevideoSourceis a FlashVars variable of the same name.If you’re dealing with the FLVPlayback component prior to AS3, just reference the FlashVars variable directly (no need for the
root.loaderInfo.parametersobject reference). Prior to AS3, thesourceproperty is calledcontentPath.More detail here: “How to Retrieve FlashVars Data in ActionScript 3.0” and here “How to Tell a SWF What File(s) to Load — From the Outside” (AS2).
April 29th, 2008 at 4:09 pm
great post, great comments. i spend lot of time reading you. very useful info. thanx for sharing knowledge.
May 1st, 2008 at 12:35 pm
Such a great thread! My problem is simple, but the solution is elusive (to me).
My video is loading perfectly fine. But when it ends, it goes to black. I’d like to give the user something more interesting to look at.
How do I tell the Flash file to load a new FLV or SWF (I guess on a new level) when the video is over?
Cheers!
May 1st, 2008 at 1:43 pm
Actually, it would be even better if I could just tell my movie to play frame 2 when the video is over.
Can I do this??
May 7th, 2008 at 10:58 pm
To daniel …
Thanks! Glad to hear that. It always makes me smile when I hear that someone gets something out of these posts and replies.
To Joe …
The trick to what you’re after is determining when the video has finished playing. There’s an article on that topic here: “How to Determine the Completion of a Flash Video (FLV) File (AS2),” so see if that gets you started.
May 8th, 2008 at 10:56 am
how would i add player controls? Similar to a FLVcomponent?
May 8th, 2008 at 11:06 am
manny,
Rolling your own can potentially get complicated, but here are a few pointers:
How to Control Video (FLV) without a Component
How to Fast Forward and Rewind Video (FLV) Content
How to Build a Flash Video (FLV) Progress Bar
May 8th, 2008 at 11:18 am
Hello Dear David..
So i used the code for my magazine. I’m using a magazine system for windows application with flash. Anyway.. I used the cod but there’s a problem in the components. The code is working in my local but i wanna use an URL for the ‘ns.play(”externalVideo.flv”);’ like this;
ns.play(”http://www.blabla.com/blabla/video.flv”); but it’s not working then the browser is guiding me to the Settings of Adobe flash site… isn’t there any solution for URL alternative?
May 8th, 2008 at 12:51 pm
David,
Thanks a million for all the help you provide on this site. It’s great to find people who help just to help. I have been trying to make html-based links that will load different videos into a player, all without a page refresh. I think I am about there with what I have read on your blog, but I am running swfobject 2 (not very well either), and I don’t know how to declare the flashvars (i guess?) to be able to send the video file name to the ns.play in the actionscript. I see how to do it in swfobject 1.x, but it seems to change. Can you maybe shed a bit of light?
I have the player there, and it will play static files, but when I replace the video url with a variable, and even have a text field show that variable, it never makes it in to the flash file. thanks very much once again.
May 8th, 2008 at 1:33 pm
actually, i have managed to get the flashvars into the player with:
var flashvars = {};
flashvars.video = (”videoname.flv);
and it will load the video that I want, but I need to be able to add this video=whatever.flv to be attached to an html link that won’t refresh the page, but rather sends that video to the netstream…
once again, thanks. I was at a roadblock before I found this site.
May 20th, 2008 at 12:21 am
Hi David,
Some time ago someone posted about playing a .flv file over UNC - did you ever work out a solution to this one?
FLVs can be very handy for internal networks but without UNC functionality the whole thing relies on drive mappings which aren’t always consistent…
Thanks for th great info
May 20th, 2008 at 11:24 pm
To Fatih …
Is your magazine something that gets distributed on CD-ROM? I ask, because the security sandbox has significantly changed in Flash Player over the years. Flash Player 7 was stricter than previous, and Flash Player 8 tightened that even more (and then 9 … you get the idea).
The long and short of it is, Flash Player (and most browsers, nowadays) are simply going to warn the user when local content — such as files on a CD-ROM — try to access the Internet. These are paranoid times.
To Mike …
Sorry I missed your question! I’m working on two books right now, which has been a real challenge to my evening routine.
I’m glad you figured it out! Good for you!
To Daniel …
I’m checking in with a colleague on this one, Robert Reinhardt (Flash Bible), and will post back if I get a definitive answer.
June 11th, 2008 at 8:09 am
I am fairly new to ActionScript 2.0 and love your blog which has helped me make my SWF skin for Flash 8 and higher.
However, I am seriously struggling with the .swf and .flv running on a web server. It executes just fine on the local and internal mapped network drives, but when I place the following files on the internal web server, only the .swf skin appears and the progress bar constantly cycles and the dynamic time display never goes past 0:00. I can’t get my FLVPlybk to run when the files are on the web server only when they are ran from my local network.
I have also tried the NetConnection and NetStream and it didn’t work. However, I don’t think my employer has Flash media Server loaded on the web server.
1.) swfobject.js
2.) MCB_20_Contract_Formation.swf
3.) MCB_20_Contract_Formation.html
4.) Contract Formation_FINAL.flv
Below is the ActionScript 2.0 from my frame 1. I have tried to include the following attachMovie but it still won’t work. I get the error “The class or interface ‘FLVPlayback’ could not be loaded.” I need some help I have worked on this for 4 days and can’t get it to work.
// Attach the container clip
var myVideo:MovieClip = this.attachMovie(”videoHolder_mc”, “myVideo”, 0);
// Set interval that waits a millisecond
var wait:Number = setInterval(this, “onWaited”, 1);
// Method executed once interval is triggered
function onWaited():Void
{
trace(”onWaited”);
// Clear the interval so it doesn’t call this method over and over
clearInterval(wait);
// Load up the video
var vp:FLVPlayback = myVideo.vp;
vp.skin = “MCB_20_Contract_Formation.swf”;
vp.contentPath = “Contract Formation_FINAL.flv”;
}
import mx.video.*;
my_FLVPlybk.backButton = my_bkbttn;
my_FLVPlybk.forwardButton = my_fwdbttn;
my_FLVPlybk.playButton = my_plybttn;
my_FLVPlybk.pauseButton = my_pausbttn;
my_FLVPlybk.stopButton = my_stopbttn;
my_FLVPlybk.seekBar = my_seekBar;
my_FLVPlybk.bufferingBar = my_buffrgbar;
my_FLVPlybk.volumeBar = my_vBar;
my_FLVPlybk.contentPath = “Contract Formation_FINAL.flv”;
June 17th, 2008 at 5:27 am
I’ve created an intro for my website using flash. I had first embeded a video that is basically a clip of someone talking. The sound after being embedded wasn’t very good at all. I then created an flv file which I’ve included using a flv playback in my flash into. The flash intro includes text that I displayed during pauses in the flv video.
My issue now with the progressive download is that I can’t match up the video with the flash.
Do you know if there is a way to start the progressive download at the beginning of the swf but actually start playing it at a particular point in the timeline?
I appreciate any help or advice.
June 19th, 2008 at 11:35 am
To Daniel …
I checked with Robert Reinhardt, and he said UNC paths have worked just fine for him. Interesting, right? So I tried a quick demo myself — loading both an MP3 file and an FLV — at at first, my test failed. But then I noticed something. In UNC paths, of course, the slashes lean back — they’re backslashes (
\) — and that’s the punctuation used for escape sequences.If my UNC path was, say, \\Grendel\videoFile.flv, then ActionScript might actually interpret that as \Grendel\ideofile.flv. The v disappears because it is escaped by the backslash that precedes it. Only one backslash appears before the G because in the case of backslashes, a preceding backslash indicates the second backslash should be taken literally.
To correct that, you would have to use this:
\\\\Grendel\\videoFile.flv… and in my tests, that works for code-based references. The FLVPlayback component doesn’t seem to need the extra backslashes; at least, not on my machine.
To Moneissa …
If you’re calling the FLV file from Flash Media Server, the
contentPathparameter needs a different value, because Flash Media Server uses a different protocol to deliver files (rtmp, rather than http). This difference affects both FLVPlayback and theNetStreamapproach.With
NetStreamover rtmp, you don’t passnullto theconnect()method of yourNetConnectioninstance. Instead, you pass in the path to the relevant Flash Media Server folder.With FLVPlayback, you’ll have to precede the reference to your FLV file with
rtmp://.Let me know if that does it for you! If not — because, for example, you’re not using Flash Media Server after all, or for whatever reason — let me know.
To Jessica …
You can start a progressive download then immediately pause playback (
Netstream.pause()orFLVPlayback.pause()), then resume again when enough of the FLV has loaded. TheNetStream.bytesLoaded/bytesTotalandFLVPlayback.bytesLoaded/bytesTotalproperties give you the values you need to determine how much of the video you want to load before proceeding.The “How to Tell When an External SWF has Fully Loaded” article on this blog will give you a basic run-down on how to compare
bytesLoadedandbytesTotalproperties to determine how much of an external file has loaded. You’ll probably want to pause the main timeline while you wait, and then you feel that enough of the file has come in (maybe half, maybe all?), you can send the main timeline to whatever frame you like, where another bit of keyframe code will invoke the appropriate resuming method on yourNetStreamorFLVPlaybackinstance (invokepause()again forNetStreamorplay()forFLVPlayback).June 19th, 2008 at 4:03 pm
Hi David:
You are a real gem of evidence that the internet can be a source of information and selfless generosity.
I know this blog was targeted specifically for run-time flv scripting, but my question is a hybrid one:
I know that I can use my existing FLVPlayback component (which currently works fine for progressive flv’s) for true Flash Video streaming, but will FLV Playback work with in conjunction with netConnect & netStream bandwidth detection script?
Greatly appreciate your valuable time and knowledge.
June 19th, 2008 at 7:09 pm
Hey David,
You. Da. Man! (and kudos to Robert Reinhardt too!).
First test worked nicely with the .flv in a .swf, and though up until now I’ve simply been using Dreamweaver to embed the .flvs into .htmls, I’ll happily change the system if my second test doesn’t work (.flv straight into .html).
Thanks heaps for the info, I googled over a whole day away trying to find a solution, and as it stands now, this is the only place on all the internets with this information written down!
Thanks again
June 19th, 2008 at 7:44 pm
Daniel,
Glad to hear that! Here’s hoping it works for you. Let me know how it goes!
June 27th, 2008 at 12:05 am
Sir,
I have read your loading external flv file, but i want to a continuous play ie in loop.
if you have any more please send it to me.
Thanks & Regards
Sumantra
July 16th, 2008 at 3:08 pm
Hi David.
Firstly, thanks for the great script, it’s helped immensely.
At first I had the same problem as a few other of the comments on here - audio, but no video. I changed the instance name from ‘videoplayer’ to ‘vid_player’ and now I get both. I have no idea if this was dumb luck - it certainly wasn’t skill - but I thought I’d share.
Thanks again.
John.
July 16th, 2008 at 3:10 pm
One more thing - did you ever solve this problem?
“Bravo, really. Quick question: is there a way to add some sort of listener in AS to see when the FLV is finished and send the playhead on to the next frame? Some kind of if/else statement?”
Thanks.
September 10th, 2008 at 7:13 pm
Hi David,
I have been enjoying reading this ongoing article on Flash Video.
I noticed you spoke about writing a article on XML and FLV.
Did this ever come about.
I am currently trying to find a way to auto load a
FLV into a swf from an XML document.
I know it can be done, I just would like to know how to do it myself.
This swf is also loading information into dynamic text boxes at the same time.
The idea is to have my CMS create an XML doc that has all the information for teh dynamic text boxes and the FLV info that will then load to the SWF Container via actionscript.
I could buy a XML Video Component from somewhere, but I would then still have the issue of having a 2 XML docs to deal with when I only want one.
September 24th, 2008 at 2:34 pm
Hi David,
I am trying to load my flv, (it’s working) send it to a frame label after it is finished playing.
the colde I am using does not go to the next frame, can you see what I am doing wrong?
The video loads and plays, but then just stops and does not proceed to frame label “alice”
thanks!
[code]
//actionscript 3.0
this.stop();
import fl.video.*;
var flvPlayer:FLVPlayback = new FLVPlayback();
addChild(flvPlayer);
flvPlayer.source = “http://www.helpexamples.com/flash/video/water.flv”;
video1.addEventListener(VideoEvent.COMPLETE, onPlaybackComplete);
function onPlaybackComplete(ev: VideoEvent):void {
gotoAndStop(”alice”);
}
[/code]
September 25th, 2008 at 4:56 am
Hi,
I am new to Flash development. I have created a flash player. It was working fine with I tested locally (by double clicking the file in the folder)
I have used both
c:\Player.swf?flvurl=S1.flv
c:\Player.swf?flvurl=\\SYS02\transfer\S2.flv
both were working fine.
When I uploaded the file in IIS server (SYS01), it stops playing. It plays the
http://SYS01/mySite/Player.swf?flvurl=S1.flv
but not
http://SYS01/mySite/Player.swf?flvurl=\\SYS02\transfer\S2.flv
Player.swf and S1.flv are in the same folder.
S2.flv is in Machine SYS02, in which SYS01 user is administrator. The shared folder is given full access to Everyone.
in SYS02 machine’s Administrative tool -> computer management -> Open session and file, i can see the S2 file being accessed whenever I access the site. But It’s not playing.
Can someone tell me why?
This is quite urgent for me.
Please mail me if you have any answer.
Many Thanks.
Cheers,
Bala
balaji.mk@gmail.com
September 25th, 2008 at 5:57 am
P.S:
I hardcoded the path in the code as
flvurl = “\\\\SYS02\\Transfer\\S2.flv”;
flv.contentPath = flvurl;
even in this scenario, it works fine when access the SWF locally (c:\player.swf), but not when accessed in Webserver (http://SYS01/mySite/player.swf).
Any clue?
Cheers.
September 25th, 2008 at 1:20 pm
To Sumantra …
For that, you need to detect the end of the video and instruct the FLV to seek to the beginning. You can see several approaches in “How to Determine the Completion of a Flash Video (FLV) File (AS2),” but in a nutshell (for non-FLVPlayback usage) you’ll write an event handler for the
NetStream.onStatusevent.To John …
By using
videoplayer(all lowercase), you might have been tapping, by coincidence, into a reserved word. That happens to me every now and then, it’s frustrating because generally speaking, you can name a variable whatever you like, as long as you adhere to the usual caveats (not punctuation other than$and_, no starting a variable name with a number, etc.).Wow, that was a long time ago! I do remember Mark’s question, and in all this time, I’ve come to the conclusion that the
onStatusapproach — the one I just suggested to Sumantra — is the easiest way to go. (I hinted at that to Mark, way back when, but was more comfortable at the time with the solution I ended up posted to the link in my previous reply. Unlike my suggestion to Sumantra, you wouldn’t invokeseek()in that event handler. Instead, you would invokeMovieClip.play(),MovieClip.gotoAndPlay(), or the like, in place ofthis.seek(0).To Joseph …
I haven’t yet written a blog tutorial on loading FLVs from XML, but the good thing about the process is, once you learn it, you can reuse the same principle for any sort of file. There’s nothing special about XML in relation to FLVs versus MP3s versus JPGs. To an extent, you could even start by listing out your FLVs in an array, then setting up a variable to count through the indexes of that array. In terms of the suggestions in my replies to John and Sumatra, you could increment that counter variable at the end of each video, like this:
Of course, doing it that way means the counter would eventually exceed the number of elements in the array. You could work around that with an
ifstatement:For XML, it would be similar enough (and would depend, of course, on the arrangement of XML nodes you decide to use). In the case of XML, you would (somewhere along the line) have a series of, say,
<video>tags, and your counter variable would loop through those in the same way.Does that help get you started?
To Jan …
The culprit is this line here:
video1.addEventListener(VideoEvent.COMPLETE, onPlaybackComplete);… because you’re associating your event handler with an instance named
video1, instead of the variable name you actually give yourFLVPlaybackinstance (flvPlayer).To Balaji …
I’m afraid I haven’t used UNC paths in client work, so I don’t have any personal insight into why you might be seeing the issues you’re seeing. I have heard from people who do use (or who have used) UNC paths successfully, but I don’t know if they were using IIS, Apache, or some other software.
Sorry I can’t help you on this one! If there’s any way you can route that path through an HTTP address, that’s worth a shot, for sure.
September 26th, 2008 at 1:19 am
David,
Thanks for the prompt reply.
But, we require IIS to be set up in the destination machine if we want to use the http instead of UNC, that is almost not possible in my scenario.
For now, we have decided to copy the files temporarily to the local folder and clean up when done playing locally.
once again, Thanks for your prompt reply.
Cheers.
September 28th, 2008 at 2:57 am
Dear David
I want to use curPoint in my FLVPlayer in Action script 2 . Could you suggest me how can i use it as well as handle the event for the same.
Regards
Animesh
September 28th, 2008 at 7:48 pm
Animesh,
Check out this article, “How to Use Flash Video (FLV) Cue Points.” That should give you a good start, if not meet your needs entirely. Write back in a comment for that article if you have specific questions after reading and experimenting.
October 10th, 2008 at 9:43 am
Hi David,
I found your blog very interesting. In fact i have a similar kind of requirement where i want to develop an audio player in flash that can play .wax files.
The url of the file goes like this:
http://[sitename]/[filename].wax
and my code goes like this:
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
videoPlayer.attachVideo(ns);
ns.play(”http://[sitename]/[filename].wax”);
Just tried out the same code that i saw above.
This audiostream url when opened in browser, plays the song in the system default player.
But its not working.
Can you help me out?
Regards,
Nisha
October 10th, 2008 at 10:42 am
Nisha,
WAX files are just pointers — just XML documents that point to other files — and the files they point to are WMA files, which Flash doesn’t support. I suppose you could use the WAX format (that particular arbitrary XML structure) and have it point to MP3s instead. In that case, you’d have to load that WAX file as you would any other XML document and parse it to locate the actual file names.
In your
ns.play()line, you’re asking theNetStreaminstance to play an XML file. It can’t, so it sounds like your operating system is doing the best it can with the requested file. Instead, you need that parameter to point to a Flash-compatible audio file. Actually, this shouldn’t be an audio file at all: it needs to be a video file!If you want to build an audio player, you should be using the
Soundclass … you can omitNetConnection,NetStream, andVideoaltogether.November 3rd, 2008 at 1:09 pm
I used the NetConnectionNetStream for a video player and when I test it swf it works perfectly. All the controls, the buffer, scrubber, everything fine. When I test in a browser, everything works but the video. I can hear audio and scrub it, just can’t see it.
November 24th, 2008 at 2:36 pm
Hello, David
Im new in scripting and i used 2 buttons, so when i would click on each the video would play in component. I tried different things and nothing.
When i test it and when i click on button video doesnt play in component.
thank you
function showVid1(evt:MouseEvent):void{
vidComp.source = “flash/short_jump.flv”;
}
vid1.addEventListener(MouseEvent.CLICK,showVid1);
function showVid(evt:MouseEvent):void{
vidComp.source = “flash/odpirazapira.flv”;
}
vid2.addEventListener(MouseEvent.CLICK,showVid);
November 25th, 2008 at 10:44 am
To Cou …
Off the top of my head, I’m afraid I can’t think of a solution. Have you tried reproducing your code — just the bare essentials — in another FLA file?
To Robert …
This article is written for ActionScript 2.0 (AS2), and the code you’re showing is ActionScript 3.0 (AS3). That said, your code looks fine. Are you trying this in a FLA file configured for AS3? Is the component’s instance name
vidComp? Setting thesourceproperty may not be enough, either. You might also have to actually instruct the component to play:November 29th, 2008 at 7:07 pm
Hey, how could I attach the Video object dynamically to the stage?
this.attachMovie(”Video1″,”video1_video”,this.getNextHighestDepth());
am I not casting the correct type for this object?
thanks what a wonderful resource.
December 1st, 2008 at 11:58 am
I thought the best way to attack this was to create an mc called movieHolder and then have the Video object inside of that which I could call as needed, but I think I have some details that need ironing out.
December 1st, 2008 at 12:20 pm
Patrick,
Yeah, it’s a bit cumbersome in ActionScript 2.0. In AS3, you can create a
Videoinstance simply by instantiating it:var videoPlayer:Video = new Video()… which then eventually needs to be added to a display list:
addChild(videoPlayer)In AS2, however, certain objects can’t be created with the
newkeyword. This list includes (at least) movie clips and videos. YourattachMovie()workaround is definitely the way to go, but you’ll notice that Video objects can’t be given a linkage identifier, so they can’t be attached directly at runtime. In addition, theMovieClip.attachMovie()method is specifically aimed at movie clips, which aren’t related to theVideoclass in AS2.As long as your
Video1asset is a movie clip symbol, you should be all right. Give that movie clip a linkage identifier (which you’ll need forattachMovie()), and make sure that movie clip has a made-by-hand Video object inside it. In other words, create a Video object in the Library, then add it to Layer 1, frame 1 of an otherwise empty movie clip symbol. Make sure to give the Video object an instance name inside that symbol.Then, when you attach that movie clip at runtime, you’ll be able to reference it by way of its own instance name (your second
attachMovie()parameter). Follow that instance name with a dot, then provide the instance name of the Video object, and your full object reference will work just fine.Does that make sense?
December 1st, 2008 at 12:59 pm
absolutely made sense. stupid error on my part to forget linkage. Thanks.
December 1st, 2008 at 1:26 pm
Patrick,
Sweet! Glad to hear that. Don’t worry yourself about it, man. I forget to dot my
is and cross myts all the time.December 2nd, 2008 at 3:11 am
Problem loading multiple FLV files.
Thanks for the post. It works for me for 3 or 4 instances, but I start having trouble when i have more instances. My objective is to load several, lets say 10 small FLV files into memory, so that I can quickly switch between them.
I created a simpleflv object that incorporates basically all of your code…a netconnection, netstream and video object.
Im tracing all of the NetStatus events… things work great, and then at some point, some of the NetStream objects just stop working, i dont get see any more events fired when I try to call stream.seek(0).
I hope this is not to vague - just wanted to see if you (or anyone) had encountered this problem and have any clues. I saw some other similar symptoms:
Similar at the bottom:
http://www.ultrashock.com/forums/actionscript/as3-flv-preloader-91343.html
“buffer the video stops playing and wont resume and I don’t even seem to get any NetStatus Events or any other obvious errors or events.”
Thanks! - topher
December 2nd, 2008 at 12:34 pm
I added some online tracing code to display the netstream.bytesLoaded and netstream.bufferLength on each instance. Everything is cool till i add a 5th instance to the stage, then all instances go to 0 on all values. Its like the garbage collector kicked in or something. But even the new instance is not playing! Hmmmm.
December 3rd, 2008 at 7:26 am
Oh, sorry i didnt pay attention that is as2, but i solved problem, instead of / i put \ and it worked.
Thanks for reply, robert
January 10th, 2009 at 9:47 pm
I don’t know if this would help someone… i hope so.
// load the xml file
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load(”videos.xml”);
// parse the nodes of the xml into an array
function loadXML(){
vidArray = new Array();
aNode = this.firstChild.childNodes;
len = aNode.length;
for(var n=0;n!=len;n++){
vidArray[n] = aNode[n].attributes.url;
}
};
// buttons
video1_btn.onRelease = function(){
trace(vidArray[0]);
// videoObj_1 - instance name of FLVPlayback component
videoObj_1.contentPath = vidArray[0];
};
video2_btn.onRelease = function(){
trace(vidArray[1]);
videoObj_2.contentPath = vidArray[1];
};
Sorry about my english… i just speak spanish
January 10th, 2009 at 9:52 pm
and this is the xml.
this will load external movies from an xml… includes buttons in order to play different movies. If you need any help to play movies “automatic” (sorry I don’t know the word in english) or need help to play just 1 movie, leave a post. (please in spanish or very simple english)
January 10th, 2009 at 9:55 pm
January 23rd, 2009 at 12:38 am
David!
Thanks for valuable information. It helped to me understand FLV’s.
March 6th, 2009 at 10:59 pm
Hi David.
I have a question. I know how to change the mouse pointer and works really good but… How do I change it just on an event? I mean I need to change the mouse pointer on rollover and it must be different according to the button. Is it possible?
May 11th, 2009 at 8:57 pm
David very very thanks for this video guide but I got problem in this script that i am using FLASH MX Pro 2004 but when I press ctrl+enter to test movie it displays blank, only showing BG color which is white , I have flash player 10 version installed … please tell what the problem is here
June 14th, 2009 at 2:13 pm
I have searched high and low for hours all over the web looking for a tutorial on preloading an flv. in actionscript 2.0 Then I came across your blog and I have begun to understand a few more things but I can sure use your help on this subject as I have a client that does not want a regular preloader but one that will load at least 50% of the flv in buffer time and display the result while the user waits for the flv to load. This would need to be built with a text that will flash repeating until the correct set amount of the video loads. One of the places I’m stuck is which tut do I follow as I already have the flv component on the stage with a skin for stop and playback. As I wait for your answer I’ll have a look and read all your tutes on this and try to figure out.
I would have thought that just adding the buffer bar component and a little AS would have done the trick but I guess I’m way off here.
June 19th, 2009 at 2:20 pm
hi all, well i found the following code (AS3) working pretty well…
var videoPlayer:Video = new Video();
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
ns.play(”external_flv.flv”);
videoPlayer.attachNetStream(ns);
addChild(videoPlayer);
am no expert… found this by hit and trial..
i just had a question that…
how do i adjust the flash player height and width dynamically according to the external flv file?? as of now the flash player has static dimensions!!! do i need to use the scale movie property??
June 22nd, 2009 at 11:37 am
This code, to load FLV’s from XML works great, but it is on a button press. I really need to have this work automatically (not on button press). I have had no luck finding out how to do this one the web. Any help would be great.
// load the xml file
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load(”videos.xml”);
// parse the nodes of the xml into an array
function loadXML(){
vidArray = new Array();
aNode = this.firstChild.childNodes;
len = aNode.length;
for(var n=0;n!=len;n++){
vidArray[n] = aNode[n].attributes.url;
}
};
// buttons
video1_btn.onRelease = function(){
trace(vidArray[0]);
// videoObj_1 - instance name of FLVPlayback component
videoObj_1.contentPath = vidArray[0];
};
video2_btn.onRelease = function(){
trace(vidArray[1]);
videoObj_2.contentPath = vidArray[1];
};
June 22nd, 2009 at 11:41 am
my biggest thing is that i can’t use netstream and everything is setup around a the flvplayback component (because i am using actionscript cuepoints in AS2) and netstream doesn’t support this. My client now wants all files remotely loaded through .xml. I have each video in loaded into an individual .swf and from the main wrapper, i just need make them accessible from .xml.
August 1st, 2009 at 2:52 pm
Hello fellows,
I am having some issues with one episode.
When movie compiles it loosening a connection with one FLV files (at root directory with the swf). It drops about 19 lines of code about “Virtual PLayer”.
It was actually very irritatingly in and out. Like if I’ll hit “Ctrl+Enter” one after another then sometimes it compiles ok and video plays, but mostly don’t. I killed “mx” folder, trying again - noway, video is not showing.
Any thoughts, please?
Kolyan
September 8th, 2009 at 9:11 am
How would I incorporate the onComplete Function in to this code I already have. I have to use the code below:
stop(); // stop the page from playing
trace(”This=”+this)
// this makes sure that all_rise.flv can be found at run time and dev time
if (_parent) // only true if embedded in another SWF like pageFlip
{
// live, wait till the unmute signal is sent
FLV.contentPath=”pages/all_rise2.flv”;
FLV.autoPlay=false;
}
else
{
// during testing we want the video to start immediately
FLV.contentPath=”all_rise2.flv”;
Signal(”unmute”);
}
function Signal(msg:String)
{
switch(msg)
{
case “mute”: FLV.stop(); break; // this signal can be issued several times.
case “unmute”: FLV.play(); break; // this signal is sent once only.
}
}
Thanks
October 27th, 2009 at 8:48 am
This is brilliant!
Is there anyway to have it paused at the start and then a simple play/pause button next to it?
October 27th, 2009 at 9:01 am
Sorry. What i meant was…
I don’t have any controls on it.
Is there a way to have it paused at the begining and then when clicked it plays?
January 22nd, 2010 at 2:22 pm
Hi David.
I just want to say THANK YOU for your blog and helpful thread.
After spending all day trying to set up a video player that initially loads a random flv and then also allows you to play specific flv’s using buttons, I finally stumbled upon this thread and you saved the day! It’s working great.
Thanks again!
Veronica
January 25th, 2010 at 10:21 am
Hello David.
First of all: Thanks a lot for this blog. I used this topic to do one of my MA projects last year and it worked out very well. But I had to update the application and something is not working properly any more. I just do not know, what it is…
I have a starting loop at the beginning (Framelabel “Loop”):
Script-Layer 1
stop(); // so that the whole comp stops here
Script-Layer 2
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
videoPlayer.attachVideo(ns);
ns.play(”Content/00_Loop.flv”);
ns.onStatus = function(evt:Object):Void {
if (evt.code == “NetStream.Play.Stop”) {
this.seek(0);
}
};
With some buttons you can start a separate movie
on (release, keyPress “p”) {
gotoAndPlay(”Clip”);
}
and there this one starts…
var duration:Number = 0;
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
videoPlayer.attachVideo(ns);
ns.play(”Content/01_Cycle.flv”);
ns.onMetaData = function(evt:Object):Void {
duration = evt.duration;
};
ns.onStatus = function(evt:Object):Void {
if (this.time > 0 && this.time >= duration) {
gotoAndPlay(”Loop”);
//trace(”Video complete”)
delete this.onStatus;
}
}
It was working like that very well, but since I have updated to CS4 and using the Flashplayer 10, the video doesn’t go back to “Loop” but stops at the last frame of the Clip-Film.
Could it be Flashplayer 10?
Or is something wrong with my script?
January 25th, 2010 at 12:32 pm
Hey David,
Love your blog. I had a question for you regarding loading an external FLV on my website.
My site is set up, loading external SWFs into an empty movie clip on the “home” flash file. This home page has a series of buttons that call the external SWFs into the movie clip using this code:
on (release) {
if (_root.currMovie == undefined) {
_root.currMovie = “main”;
container.loadMovie(”main.swf”);
} else if (_root.currMovie != “main”) {
if (container._currentframe >= container.midframe) {
_root.currMovie = “main”;
container.play();
}
}
}
But, one of the buttons, I would like to call an external SWF into the movie clip that streams an FLV. This “movie” external SWF uses the code from this article to stream the FLV which works fine, but when I click another button on the “home” page to unload that SWF and load another it doesn’t work.
I can’t figure out how to stop the NetStream, unload it and load the new SWF.
If you could help me, I’d really appreciate it.
Thanks a million.
Bart
January 25th, 2010 at 4:59 pm
Hello again. Sorry, but I think I found the mistake… It is neither the Flashplayer nor the Coding. It seems to be the new CS4 Media Encoder which creates different FLV’s. I remade them with the Flash CS3 Video Encoder and now it is working. I am not 100% sure, but I think this will solve the problem.
March 7th, 2010 at 7:54 pm
David,
I am trying to load an external flv video without any embedded cuepoints. Can this be done using netconnection and adding some sort of tag to an external xml file. So when u click on an image that is loaded in the video ui side bar it can go to a specific point in the video, i.e. 2:30 NEXT IMAGE CLICK= 5:00, etc.
Any info will help. Is this possible?
Ryan