PDA

View Full Version : streaming media into flash


pelachrum
03-10-2008, 11:34 PM
i'm trying to stream a movie right into the flash movie (using the media component I'm guessing?)

can I do it right through actionscript?

inhan
03-11-2008, 12:50 AM
Yes, but you need to have that component in your library.

pelachrum
03-11-2008, 01:02 AM
...actually correction, based on some digging around I see that I don't want the controls visible... I don't know much about this nook of Flash... here's what i have
import mx.video.*;
this.attachMovie("FLVPlayback", "my_FLVPlybk", 1000, {width:345, height:296, x:100, y:100});
my_FLVPlybk.contentPath = "testFile.flv";

...few things, i'm guessing the 1000 is the length of the video it will buffer before it plays, right?
also, even though width:345, height:296 are the dimensions of my flv file, the video is smaller when i test it and playing with those numbers has no effect on the size...

inhan
03-11-2008, 03:25 AM
1000 is the depth and every other value is what you think it is.
The reason of that problem/issue is, the default for a FLVPlayback instance is autoSize=true. And it is recommended to set the size after attaching it. Check the example:

import mx.video.FLVPlayback;

var flv:FLVPlayback = this.attachMovie("FLVPlayback", "my_flv", 100);
flv.setSize(400, 200);
flv.autoSize = false;
//flv.maintainAspectRatio = false;
// comment and uncomment the previous line to see the difference.
flv.contentPath = "video1.flv";

var listener:Object = new Object();
listener.ready = function(evtObj:Object) {
trace("width:"+evtObj.target.width+", height:"+evtObj.target.height);
};
flv.addEventListener("ready", listener);

dannyhouk
03-11-2008, 06:26 AM
...actually correction, based on some digging around I see that I don't want the controls visible... I don't know much about this nook of Flash... here's what i have

You're basically using actionscript to build your flv playback component, whereas you could as Inhan suggested just drag the FLVPlayback component onto the stage, give it an instance name, and then use actionscript to control how you use it. Whether the flv has its own buttons or not depends on how you published your flv. For the playback controls you can select "none" when publishing in which case the flv you call will not have its own controls, only what you select from the components library.

pelachrum
03-11-2008, 02:04 PM
yeah that explain everything, thanks guys
how do I loop this movie to start from the beginning when it's done?

inhan
03-11-2008, 06:30 PM
A correction to Danny is, I'm not creating an instance on the stage. I'm just keeping a FLVPlayback instance in the library. The reason you use attachMovie rather than createClassObject is the fact that the FLVPlayback class extends the MovieClip class.

Additionally, to make it loop, use the 'complete' event handler:

var listener:Object = new Object();
listener.complete = function(evtObj:Object) {
evtObj.target.play();
};
flv.addEventListener("complete", listener);

pelachrum
03-11-2008, 06:41 PM
thanks Inhan, works like a charm

inhan
03-11-2008, 07:35 PM
You're welcome. You might need to check the documentation for aditional features.

Cheers.

pelachrum
03-12-2008, 05:29 PM
do you know by any chance if there is a way to dictate how much of this media file is streamed before it is played? I'm getting pretty decent performance but it does get a bit choppy in the beginning... I'm wondering if I could delay the play a tad or buffer somehow?

inhan
03-12-2008, 11:45 PM
Let's see what documentation offers.

inhan
03-12-2008, 11:49 PM
Documentation reads the following data:

FLVPlayback.bufferTime

Description:
Property; a number that specifies the number of seconds to buffer in memory before beginning to play a video stream. For FLV files streaming over RTMP, which are not downloaded and buffer only in memory, it can be important to increase this setting from the default value of 0.1. For a progressively downloaded FLV file over HTTP, there is little benefit to increasing this value although it could improve viewing a high-quality video on an older, slower computer.

NOTE:
This property does not specify the amount of the FLV file to download before starting playback.

pelachrum
03-16-2008, 09:55 PM
i'm trying to attach a play button when this flv is complete which will play it from the beginning (in this instance I don't want autoplay). i have this... but the button is neither showing or working... well obviously it's not there...

var listener:Object = new Object();
listener.complete = function(evtObj:Object) {
_root.createEmptyMovieClip("playBtn_mc", _root.getNextHighestDepth());
_root.playBtn_mc.attachMovie("play", "play_mc", _root.playBtn_mc.getNextHighestDepth());
_root.playBtn_mc._x = 100;
_root.playBtn_mc._y = 100;
playBtn_mc.onPress = function() {
evtObj.target.play();
}
};
flv.addEventListener("complete", listener);

atomic
03-16-2008, 09:59 PM
On some .flv's, sometimes the complete event doesn't fire up... That might be your problem...

pelachrum
03-16-2008, 10:12 PM
On some .flv's, sometimes the complete event doesn't fire up... That might be your problem...

you're suggesting that it may be down to the particular flv file or that it's a random thing that happens? I have few other flvs where the complete function works, i'm thinking if i should trust that if it works now for those it will work forever or should I be looking for a workaround for all these flvs...

atomic
03-17-2008, 01:12 AM
Are you saying that with another .flv, your above script works fine? Thus proving that the previous .flv is the culprit?

What I'm saying is that it doesn't happen randomly... But it happens with (I can't remember which...) either with .flv's that don't have sound, or is it with .flv's that have sound, but the sound ends before video, or is it after, or is it because of some audio codec used in the encoding... In any case, it definitely seems audio related...

You could probably add insurance that your button would appear, if on top of the complete handler/listener, you either added a ending cue point in the video, or using an onEnterFrame check if the playhead position matches the flv's duration.

inhan
03-17-2008, 01:14 AM
Does it output anything at all when you use the trace function inside the complete event handler?

pelachrum
03-17-2008, 01:53 AM
atomic, yes it is indeed the only flv with audio, rest (for which complete works) are silent. I am not noticing any lag with the audio track itself though - video and audio are synced as they should be but yes, if you're suggesting presence of audio can have something to do with it then my current standing supports this idea.

inhan,
having this in the code:

var listener:Object = new Object();
listener.complete = function(evtObj:Object) {
trace("video complete");
};
flv.addEventListener("complete", listener);
DOES return the trace as it should

inhan
03-17-2008, 02:03 AM
Try this.
var listener:Object = new Object();
listener.complete = function(evtObj:Object) {
var btn:MovieClip = _root.attachMovie("play", "playBtn_mc", _root.getNextHighestDepth());
btn._x = btn._y = 100;
btn.onPress = function() {
_root.flv.play();
this.removeMovieClip();
};
};
flv.addEventListener("complete", listener);

pelachrum
03-17-2008, 03:22 AM
ok i think i know what's causing this thing... in my case
the complete handler does work as expected but it's the paths that are messing things up...
my structure as far as files are concerned looks like this:
main.swf --- (loads in this file) ---> another.swf --- (loads in the flv) ---> testMovie.flv

I just tested by targeting another mc on the main.swf timeline and it was affected by the handler as expected. In my case I think it would be safer to attach this button to the another.swf timeline as it is part of that mc (functionally speaking).
...I'm little fuzzy on the issue how to formulate such path

var listener:Object = new Object();
listener.complete = function(evtObj:Object) {
_root.buttons_mc._y = 100; //THIS IS THE TEST PART, WHICH WORKED FINE, MC IN THE TOP SWF
var btn:MovieClip = _root. NEED A PATH .attachMovie("play", "playBtn_mc", NEED A PATH.getNextHighestDepth());
NEED A PATH.btn._x = 300;
NEED A PATH.btn._y = 300;
NEED A PATH.btn.onPress = function() {
NEED A PATH?? > this.flv.play();
NEED A PATH?? > this.removeMovieClip();
};
};
flv.addEventListener("complete", listener);

...ewrrr... now i'm having second thoughts about it... could it be just the path?

pelachrum
03-17-2008, 05:15 AM
ok here are the final observations due to which i know what does not work but still don't know how to fix it. it's the code as it is worded in this instance that does not result in fulfilling the 'complete' handler (even though the handler itself works as shown by a single line of code affecting mc on root timeline). I'm assuming my paths are correct as shown below (those might be the same as you had it originally inhan). The paths I tested by using the same code outside of the handler... the only question mark here is whether the path would be actually affected by appearing WITHIN the handler (sort of like when an object appears WITHIN onPress function for instance)... this perhaps you can enlighten me on.

by the way audio doesn't seem to be a factor as i tried linking another, audio-less flv, and still no go.

var listener:Object = new Object();
listener.complete = function(evtObj:Object) {
_root.buttons_mc._y = 100; // AS ABOVE, THIS WORKS RESULTING IN MC FROM MAIN TIMELINE TO SHIFT POSITION, HENCE THE ASSUMPTION THAT THE HANDLER ITSELF WORKS

// THIS PART I CAN'T GET TO WORK... IS IT STILL THE PATHS? IS IT THE CODE AS IT APPEARS HERE...? HEAVEN KNOWS... AND INHAN, AND ATOMIC, ANY FEW OTHER... NOT ME THOUGH
var btn:MovieClip = this.attachMovie("play", "playBtn_mc", this.getNextHighestDepth());
this.btn._x = 300;
this.btn._y = 300;
this.btn.onPress = function() {
this.flv.play();
this.removeMovieClip();
};
};
flv.addEventListener("complete", listener);

// THIS BELOW HERE IS RECREATION OF THE SAME CODE BUT OUTSIDE OF THE HANDLER, THIS WORKS, PATHS (IN THIS LOCATION - OUTSIDE OF THE HANDLER?) ARE CORRECT
var btn2:MovieClip = this.attachMovie("play", "playBtn2_mc", this.getNextHighestDepth());
this.btn2._x = 400;
this.btn2._y = 400;

atomic
03-17-2008, 05:22 AM
I didn't say your problem was necessarily caused by audio...
Just saying (and there are many threads about it...) that the complete handler is unreliable in some cases...
Just wanted you to definitely eliminate that as maybe being one of the causes of you problem...

pelachrum
03-17-2008, 05:32 AM
yeah, i understand. so far it looks like it may not be the source of the problem but... time will show
thanks

inhan
03-17-2008, 05:44 AM
var btn:MovieClip = this.attachMovie("play", "playBtn_mc", this.getNextHighestDepth());

"this" here refers to the listener object so use _root, or some other scope that is a movie clip at first place.

atomic
03-17-2008, 06:01 AM
Short night! Good morning Inhan! It's goodnight for me! ;)

pelachrum
03-17-2008, 06:51 AM
i ended up defining the button in the parent swf and having only its visibility toggled in the 'complete' handler.

thanks both and yes goodnight and good morning

inhan
03-17-2008, 03:03 PM
I'm more than wondering what your result will be with the following file. Can you please let me know?

atomic
03-17-2008, 03:50 PM
Works fine for me! ;)

inhan
03-17-2008, 07:28 PM
Works fine for me! ;)
I know it should but I still can't see why it doesn't work for pelachrum.

pelachrum
03-18-2008, 04:24 PM
this works inhan. I'll go with that then
i did have to revise my scope in the part that makes the button work, ... earlier it was probably this part that was messing things up
thank you

inhan
03-18-2008, 05:31 PM
I'm glad it's solved, then..