View comments | RSS feed

Playing back external FLV files dynamically

As an alternative to importing video into the Flash authoring environment, you can use ActionScript to dynamically play back external FLV files in Flash Player. You can play back FLV files from an HTTP address or from the local file system. To play back FLV files, you use the NetConnection and NetStream classes and the attachVideo() method of the Video class. (For more information, see "NetConnection class", "NetStream class", and Video.attachVideo() in Flash ActionScript Language Reference.)

You can create FLV files by importing video into the Flash authoring tool and exporting it as an FLV file. (See "Macromedia Flash Video (FLV)" in Using Flash.) If you have Flash Professional, you can use the FLV Export plug-in to export FLV files from supported video-editing applications. (See "Exporting FLV files from video-editing applications (Flash Professional only)" in Using Flash.)

Using external FLV files provides certain capabilities that are not available when you use imported video:

Tip: To load FLV files from a web server, you might need to register the file extension and MIME type with your web server; check your web server documentation. The MIME type for FLV files is video/x-flv.

The following procedure shows how to play back a file named videoFile.flv that is stored in the same location as your SWF file.

To play back an external FLV file in a Flash document:

  1. With the document open in the Flash authoring tool, in the Library panel (Window > Library) select New Video from the Library options menu to create a video object.
  2. Drag a video object from the Library panel onto the Stage; this creates a video object instance.
  3. With the video object selected on the Stage, in the Property inspector (Window > Properties) enter my_video in the Instance Name text box.
  4. Open the Components panel (Window > Development Panels > Components), and drag a TextArea component to the Stage.
  5. With the TextArea object selected on the Stage, enter status in the Instance Name text box in the Property inspector.
  6. Select Frame 1 in the Timeline, and open the Actions panel (Window > Development Panels > Actions).
  7. Add the following code to the Actions panel:
    // Create a NetConnection object
    var netConn:NetConnection = new NetConnection();
    // Create a local streaming connection
    netConn.connect(null);
    // Create a NetStream object and define an onStatus() function
    var netStream:NetStream = new NetStream(netConn);
    netStream.onStatus = function(infoObject) {
    	status_txt.text += "Status (NetStream)" + newline;
    	status_txt.text += "Level: "+infoObject.level + newline;
    	status_txt.text += "Code: "+infoObject.code + newline;
    };
    // Attach the NetStream video feed to the Video object
    my_video.attachVideo(netStream);
    // Set the buffer time
    netStream.setBufferTime(5);
    // Begin playing the FLV file
    netStream.play("videoFile.flv");
    

Comments


recoveredfromflashMX2004 said on Jul 27, 2004 at 11:40 AM :
tinicuro said on Feb 10, 2004 at 2:14 PM :

Keep in mind that video/x-flv is not on the official IANA mime type
list at this moment: http://www.iana.org/assignments/media-types/

This might be an issue if your host requires it to be on that list.
Although the .swf mime type application/x-shockwave-flash is not on
this list either.

The full information for .flv file type would be:

Mime Type: video/x-flv
File extenstion: .flv
Required parameters: none
Optional parameters: none
Encoding considerations: FLV files are binary files, some
applications might require the application/octet-stream subtype
beeing set.
Security issues: none
Published specification: http://download.macromedia.com/pub/flash/
flash_file_format_specification.pdf


Miguel Guzman said on Mar 1, 2004 at 12:12 PM :

I followed the instructions for playing back external FLV files dynamically and it works pretty well except for when I try to do the same on a different scene other than the first.

Please, does anybody knows how the code would change in order to play back external FLV files dinamically from a scene other than the main one.

Thanks,
Miguel Guzman


No screen name said on Mar 10, 2004 at 10:24 PM :

I had the same problem with screens, the flv files will only load dynamically from the main screen but not the control or children screens as described in tutorials or most manuals. I also had this problem loading individual flv files in seperate swf movies, the 1st one will load but none after. Please help.


No screen name said on Mar 10, 2004 at 10:28 PM :

Do I have to add the net connection actionscript if I use flash professional or is there a bug in loading flv files to media display dynamically. My computer seems to be the only computer that could download this file from http, others have problems.
glenn_mx6 said on Sep 13, 2004 at 10:38 AM :
This link might be helpful to some who were experiencing problems getting the FLV to stream on the live server:

http://www.macromedia.com/support/flash/ts/documents/flv_mime.htm

i'm still working on a similar thing. hopeful.
lenbradshaw said on Oct 26, 2004 at 12:38 PM :
I used this script exactly as shown (with the correction for the status name included). When I play the resulting file I can get the audio but no video. What am I doing wrong? Thanks
shimi2 said on Oct 26, 2004 at 1:53 PM :
Check that you have a named video object on stage and that the line of code with attachVideo is correct:
my_video.attachVideo(netStream);
with the instance names matching the names you used
attachVideo specifies the video stream to play in the Video object that you create on stage.
No screen name said on Oct 29, 2004 at 9:15 PM :
following the Flash Help instructions "To play back an external FLV file in a Flash document:" exactly, the linked flv plays back properly, but the output window gives repeated error of "Statement must appear within on/onClipEvent handler".


The movie contains only
1. a video object created in the library and dragged on to Stage with the label "my_video";
2. a TextArea object on stage with the label "status";
3. the above actionscript in the first frame of the timeline.

Any ideas as to why this is happening?

tia,
Lawrence
The Help doc code is in the fist frame and is:


// Create a NetConnection object:
var netConn:NetConnection = new NetConnection();
// Create a local streaming connection:
netConn.connect(null);
// Create a NetStream object and define an onStatus() function:
var netStream:NetStream = new NetStream(netConn);
netStream.onStatus = function(infoObject) {
status.text += "Status (NetStream)" + newline;
status.text += "Level: "+infoObject.level + newline;
status.text += "Code: "+infoObject.code + newline;
};
// Attach the NetStream video feed to the Video object:
my_video.attachVideo(netStream);
// Set the buffer time:
netStream.setBufferTime(5);
// Being playing the FLV file:
netStream.play("Word034.flv");
jepo said on Oct 30, 2004 at 8:02 PM :
Please make sure that your code is on frame 1 of the Timeline (step 3). If you see that error it means your code is instead attached to an instance, not on a frame in the Timeline.

HTH,
Jen.
Rob DiCiuccio said on Feb 25, 2005 at 11:31 PM :
Having same problem mentioned above regarding playing external FLV
files from a CD-ROM (or any non-boot volume). Seems to be a Mac
issue, as I can't reproduce on WinXP.

Published SWF loads external FLV (in same directory) fine when played
through the FlashPlayer app, but when the published HTML is loaded in
the browser, the MediaPlayback component remains empty.

Copy the same set of files to the Desktop (Mac) and the MediaPlayback
loads the FLV fine. Works when published to an Apache server as well.
DOESN'T work when files are loaded in the browser from any non-boot
volume (tried on 5 different Macs running OS 10.3.x, all running latest
Flash Player 7).

Any reasons/workarounds for this? This is a MAJOR problem for
distributing browser-based projects with external FLV's on CD-ROM.
nazfarmer said on Mar 16, 2005 at 6:14 PM :
Does anyone know of a fix for the FLV CD playback on a Mac problem described above? This is a huge issue.

PLEASE HELP!!!

We are having the exact same issue Rob describes:

Having same problem mentioned above regarding playing external FLV
files from a CD-ROM (or any non-boot volume). Seems to be a Mac
issue, as I can't reproduce on WinXP.

Published SWF loads external FLV (in same directory) fine when played
through the FlashPlayer app, but when the published HTML is loaded in
the browser, the MediaPlayback component remains empty.

Copy the same set of files to the Desktop (Mac) and the MediaPlayback
loads the FLV fine. Works when published to an Apache server as well.
DOESN'T work when files are loaded in the browser from any non-boot
volume (tried on 5 different Macs running OS 10.3.x, all running latest
Flash Player 7).

Any reasons/workarounds for this? This is a MAJOR problem for
distributing browser-based projects with external FLV's on CD-ROM.
No screen name said on Mar 1, 2005 at 10:52 AM :
BarkinB said on Apr 2, 2005 at 10:16 PM :
I may have something that explains it (no guarantees)....
I made a Projector for Mac of a Flash using external FLV files played using the MediaPlayback component. Publishing created an HQX file. I put that and the FLV files on the CD. Opening the HQX, that archive has to be expanded somewhere besides the CD, so I put it the root folder of my boot drive... because... on my MediaPlayBack component, I have the URL as "file:///Blue_Boy.flv" hoping it would find the FLV in the same folder as the Projector. It didn't work anywhere else but the root of the boot disk because it's path is "/", and that's what the Mac interprets "file:///" as.

On Windows, the Projector is an EXE file, and runs directly off the CD, so the FLVs load from there as well using the same "file:///" kind of URL.
No screen name said on Apr 25, 2005 at 1:26 PM :
I've also found the problem reported above with FLV files not playing from a non-boot drive on MAC OSX.

I stripped all path info from the files, and left only the filename itself to eliminate and / or \ issues. The file(s) play fine from a web server or from the hard drive, but not from a CD or non-boot drive on Mac OS X.

The same file(s) work fine on Windows, and also on Mac OS 9, so I can only assume it's a player issue and not my code, especially as other people are having the same problem.

Can we hear some type of feedback at all on this please Macromedia folks?

Thanks,

Robin
No screen name said on Apr 26, 2005 at 6:08 AM :
I should also clarify that this only appears to be an issue with .swf files on CD. If you are using an executable file it's fine.

Robin
jepo said on Apr 28, 2005 at 3:04 PM :
Please Read: This site is only intended for documentation comments. Please use the web forums for any "how do I do something?" questions. Please use the wishlist form for any enhancement requests or bugs with Flash or Flash Player.

For clarity, I have removed many questions from this thread (which should be asked using the macromedia webforums (http://webforums.macromedia.com):

For information on RTMP, please see Flash Communication Server documentation.

For information on customizing components, see: http://livedocs.macromedia.com/flash/mx2004/main_7_2/00002028.html and http://livedocs.macromedia.com/flash/mx2004/main_7_2/00002564.html. Please ask questions using the webforums.

For information on component events, see : http://livedocs.macromedia.com/flash/mx2004/main_7_2/00002019.html

For bug or enhancement requests, please use this form with detailed reproduction steps: http://www.macromedia.com/support/email/wishform/

If you have problems playing from a specific server, please see the META comments at the top of this thread.

For ALL other questions on "how to do something", please visit the webforums above. I have recorded your questions as feedback to enhance future documentation.

Also, remember to change status_text to status_txt (this has been fixed in ths source).

Regarding the Mac CD-ROM (when not using an executable), I encourage you guys to please file bugs here (http://www.macromedia.com/support/email/wishform/) with your details to ensure the proper folks see it. I will also investigate and file a bug/further details here.

Regarding other bugs, please file them using this wishform as well. This is the correct place to post *any* bugs or unexpected behaviors in Flash or Flash Player.
jepo said on Apr 28, 2005 at 6:31 PM :
Hi again,
After looking into the Mac CD-ROM issue for linking to FLV files, I have been sent this existing Macromedia TechNote, which is very clear in outlining the issue with a solution:

http://www.macromedia.com/go/3121b301

This problem is due to the nature of the Mac OS. Please see the TechNote for a workaround that enables you to link to FLV files.

HTH, Jen.
No screen name said on May 6, 2005 at 7:37 AM :
I read the tech note, and it's not really a workaround at all. I know the Mac requires : rather than / in pathnames, but you can't practically use an absolute path for a CD based project, as you never know the path to a users CD drive (as far as I know).

I understand Macromedia's point about posting this type of thing to the bug report, but when I searched the web on this issue, this is the page I found, I therefore assume many other people will come here also, and I think it's useful for them to see these comments.

Also.. information on this problem should be added to the documentation, as I somehow doubt any fix is imminent.

Thanks,

Robin
No screen name said on May 6, 2005 at 8:11 AM :
Ok, sorry, I guess you can know the volume name.. it takes whatever you name the CD. I'm used to Windows where if looks for a drive letter.

Be nice if a summary of how to detect the OS (or a pointer to the script) could be added to the documentation on using flv, along with a note outlining that you need to use myDrive: etc. where myDrive is (or can be) the CD volume name?

Robin
jepo said on May 16, 2005 at 4:29 PM :
I have noted this as a request for future documentation. Thanks for your feedback!
Suneetha Koduri said on Sep 21, 2005 at 1:15 PM :
I am trying stream videos in using flash communuication server. My Client side script is as follows.

#include "NetDebug.as"
stop();

function initStreams() {

// Make a connection to the application on the server
client_nc = new NetConnection();

client_nc.connect("rtmp:/sample_stream");

// Handle status message
client_nc.onStatus = function(info) {
trace("Level: " + info.level + newline + "Code: " + info.code);
}

// Create input stream
var ns:NetStream = new NetStream(client_nc);
//play.attachVideo(in_ns);

}

// Connect to server and set up streams
initStreams();

function doplay() {
trace("before play");

if (play.getLabel() == "play") {

trace("in play");
// Change the button label
play.setLabel("Stop");
play_video.attachVideo(ns);
ns.setBufferTime(5);

trace("After attaching the movie");
ns.play("FenchInfluenespart2.flv");
trace("playing the video");

} else if (play.getLabel() == "Stop") {
// Change the button label
play.setLabel("Play");
ns.close();
}
}

I have an FLV video in the folder with the same name as the client-side folder in applications folder on the server side.

But it s not playing the flv on the server side.

Suneetha.
No screen name said on Dec 29, 2005 at 9:24 AM :
This comment is for the MAC CD-ROM issue. I was also having problems with the external FLV playing off a CD. I made a cross platform presentation with video and slides. The presentation cues up different movies depending on what the user chooses from a folder on the CD-ROM. The CD played on the PC and off of the MAC hardrive (when saving the contents of the CD to the hardrive) but didn't show any video when playing the CD on the MAC. ALL my other external content was able to be played. (xml documents, external SWFs and PNGs).

I tried the bug fix suggested above, but this still did not work.

To my surprise it was the CD that i was burning on. My company has us burn client projects on CDs that are screened with their logo. these unfortunately are low quality CDs. When i was testing the bug fixes on generic CDs you find at office supply stores, i had left my original version on as well. ALL the video played off of the generic CD with the original "/" in my code.

So before going through the headache of modifying your code for the MAC, try to burn it on a regular CD that you can buy at staples or office max.

Seems like a ridiculous fix, but it works!

-natasha

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/mx2004/main_7_2/00001107.html