How do I know the length of the video (external FLV video)? - actionscript-3

How do I know the length of the video (external FLV video)?
I have tried several ways but the result is 0.
videonya.addEventListener(fl.video.VideoEvent.READY, onFlvPlayback_READY);
function onFlvPlayback_READY(event:fl.video.VideoEvent):void
{
var metaDataObj:Object = videonya.metadata as Object;
trace("metaDataObj.duration: "+metaDataObj.duration);
}

The standard way of playing video and accessing metadata is this:
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
ns.client = this;
ns.play("video.flv");
var vid:Video = new Video();
vid.attachNetStream(ns);
addChild(vid);
function onMetaData(infoObject:Object):void
{
var key:String;
for (key in infoObject)
{
trace(key + ": " + infoObject[key]);
}
}
This will trace out all of the metadata codes including duration. If you just want the duration: trace(infoObject.duration); inside the onMetaData(infoObject) function, of course.

Related

play a external flv video

Hello please someone can help me with this ...
I want to play a external flv video ("../sync/video/video.flv"), but in case the video is missing or when there is a (StreamNotFound) error
I want to play automatically another flv video.
case "NetStream.Play.StreamNotFound":
ns.play("../sync/filler/video2.flv");
but it doesn't work ....
here is the full code :
var vid:Video;
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
var customClient:Object = new Object();
customClient.onMetaData = metaDataHandler;
ns.client = customClient;
ns.play("../sync/video/video.flv");
vid = new Video();
vid.attachNetStream(ns);
addChild(vid);
function netStatusF(e:NetStatusEvent):void
{
switch (e.info.code)
{
case "NetStream.Play.StreamNotFound" :
ns.play("../sync/filler/video2.flv");
break;
}
}
function metaDataHandler(infoObject:Object):void
{
vid.width = infoObject.width;
vid.height = infoObject.height;
}
You have just to add a NetStatusEvent.NET_STATUS event listener to your NetStream object :
ns.addEventListener(NetStatusEvent.NET_STATUS, netStatusF);
Then you have to assure that your second video file exist, otherwise you'll have a looping problem.
Hope that can help.

show dimension of flv in text field

Below is my basic code, im loading a flv video using flvplayback.
i need the features of flvplayback compulsorily.
I have finished loading flv video sucessfully.
Now im stuckup with showing the source video files original dimension in a text field.
How should proceed further from here. Please guide me......
stage.displayState = StageDisplayState.FULL_SCREEN;
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
import fl.video.*;
stop();
var rmys01:FLVPlayback = new FLVPlayback();
rmys01.source = "rhym01.flv";
rmys01.skin = "MinimaFlatCustomColorPlayBackSeekCounterVolMute.swf";
rmys01.autoPlay = true;
rmys01.fullScreenTakeOver = false;
rmys01.scaleMode = "maintainAspectRatio";
rmys01.setSize((stage.stageWidth/1.03), (stage.stageHeight/1.03));
rmys01.x = (stage.stageWidth/2) - (rmys01.width/2);
rmys01.y = (stage.stageHeight/1.1) - (rmys01.height/1.1);
addChild(rmys01);
setChildIndex(rmys01,1);
Did you set client for the NetStream? Because, all work ok.
Here is an example:
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
var client: Object = {};
client.onMetaData = function(data:Object):void{
//Display width and height
var textField: TextField = new TextField();
textField.autoSize = TextFieldAutoSize.LEFT;
textField.defaultTextFormat = new TextFormat("Arial", 28);
textField.text = "Width: " + data.width + ", Height: " + data.height;
addChild(textField);
}
ns.client = client;
ns.play("path/to/Video");
var myVideo:Video = new Video();
myVideo.attachNetStream(ns);
addChild(myVideo);
For debugging purposes place trace (trace("There is MetaData!");) to the onMetaData handler, check, if it triggers.
For FLVPlayback, you should subscribe for VideoEvent.READY:
rmys01.addEventListener(VideoEvent.READY, onReady);
function onReady(e:VideoEvent):void {
trace("READY");
var flvPlayback:FLVPlayback = e.target as FLVPlayback;
var metaData:Object = flvPlayback.metadata as Object;
trace("height: "+metaData.height);
trace("width: "+metaData.width);
trace("duration: "+metaData.duration);
}
If you are coding in Flash IDE, there will be a problem with VideoEvent, so you should use fully qualified class (fl.video.VideoEvent), if not, IDE will try resolve it to the flash.events.VideoEvent:
rmys01.addEventListener(fl.video.VideoEvent.READY, onReady);
function onReady(e:fl.video.VideoEvent):void {
//Handler code
}

AS3 play multy video files

I have this code for playing flv video when swf starts. How can I make it play 2 or 3 flv videos in sequence? here is the code which loads flv and plays it so I need to play two more videos after the first one automatically.
var vid:Video = new Video(1080, 720);
addChild(vid);
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
vid.attachNetStream(ns);
var listener:Object = new Object();
listener.onMetaData = function(evt:Object):void {};
ns.client = listener;
ns.play("Postvideo1.flv");
You are very close. NetStream client will help you to solve this task. More details on onPlayStatus
Establishes a listener to respond when a NetStream object has completely played a stream.
var listener:Object = {};
listener.onMetaData = function (meta:Object):void {
//Video duration
trace(meta.duration);
};
listener.onPlayStatus = function (data:Object):void {
if (data.code == "NetStream.Play.Complete") {
trace("Video playback is completed!");
//Good place to initiate playback of another video
}
}
ns.client = listener;

Streaming audio and video AS3

I have couple of videos that I'm streaming. I start with the video_1.flv and after it finishes the video_2.flv is running and looping until the user takes some action to play other movie for example video_3.flv. So I need when video_2.flv is playing in the background to be played audio file sound.mp3 witch is going to be looped , witch i managed to do. But I need both of them to run independently. Because right now when the video is looped the audio is looping to. And I need the audio to be playd only when video_2.flv is played. Thank YOU.
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
loader.vid.Video_1.attachNetStream(ns);
var listener:Object = new Object();
listener.onMetaData = function(evt:Object):void {};
ns.client = listener;
ns.play("http://media.easyads.bg/ads/display_ads_richmedia/video/avon/maria_ilieva/video_1.flv");
ns.addEventListener(NetStatusEvent.NET_STATUS, NCListener);
var clipTimer:Timer = new Timer(4000);
function NCListener(e:NetStatusEvent){
if (e.info.code == "NetStream.Play.Stop") {
ns.play("http://media.easyads.bg/ads/display_ads_richmedia/video/avon/maria_ilieva/video_2.flv");
sound.load(req);
shaker(null);
}
};
var sound:Sound = new Sound();
var soundChannel:SoundChannel;
var req:URLRequest = new URLRequest("sound.mp3");
sound.addEventListener(Event.COMPLETE, onSoundLoadComplete);
function onSoundLoadComplete(e:Event):void{
sound.removeEventListener(Event.COMPLETE, onSoundLoadComplete);
soundChannel = sound.play();
soundChannel.addEventListener(Event.SOUND_COMPLETE, onSoundChannelSoundComplete);
}
function onSoundChannelSoundComplete(e:Event):void{
e.currentTarget.removeEventListener(Event.SOUND_COMPLETE, onSoundChannelSoundComplete);
soundChannel = sound.play();
}
loader.button_01.addEventListener(MouseEvent.CLICK, play_video_01);
loader.button_01.addEventListener(MouseEvent.ROLL_OVER, play_effect_01);
function play_video_01 (event:MouseEvent){
clipTimer.stop();
ns.play("http://media.easyads.bg/ads/display_ads_richmedia/video/avon/maria_ilieva/video_3.flv");
loader.button_01_mc.gotoAndPlay (41);
}
Maybe this tutorial is helpful to you...
I'm new in AS but I'd rather prefer to pack the whole s.... stuff into a (reusable) class...
Behavior of a Loaded SWF File versus Behavior of a MovieClip
Greets
Gee

Mix and playback multiple tracks Actionscript 3

I am creating a sound mixer in AS3. I have several sound samples that a user can choose from to create their own track. The mixer will "mixdown" a max of 4 tracks and playback the "mixed" track on demand. I'm having trouble getting the sounds to playback in sync. I'm new to working with sound in flash and wondering what I'm missing... Here is the "mix" function at present:
function mixIt(e:MouseEvent) {
if (isPlaying) {
channel1.stop();
}
var mChannel1:SoundChannel = new SoundChannel;
var mChannel2:SoundChannel = new SoundChannel;
var tUrl1:URLRequest = new URLRequest(trackChoice1);
var tUrl2:URLRequest = new URLRequest(trackChoice2);
var s1:Sound = new Sound();
var s2:Sound = new Sound();
var s1Done:Boolean = false;
var s2Done:Boolean = false;
s1.addEventListener(Event.COMPLETE, onSoundLoaded1);
s2.addEventListener(Event.COMPLETE, onSoundLoaded2);
s1.load(tUrl1);
s2.load(tUrl2);
function onSoundLoaded1(e:Event) {
s1Done = true;
if (s2Done) {
playMix()
}
}
function onSoundLoaded2(e:Event) {
s2Done = true;
if (s1Done) {
trace("s2 Done")
playMix()
}
}
function playMix(){
mChannel1 = s1.play(0, 2);
mChannel2 = s2.play(0, 2);
//trace("MIXING TRACKS :" + tUrl1 + " + " + tUrl2);
}
}
try mixing sounds as byte arrays using Sound.extract() and SampleDataEvent