Streaming audio and video AS3 - actionscript-3

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

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.

Lower volume of certain audio on frame with multiple audios. AS3

Okay, so, here's the deal, i have a sound steaming from an URL since the first frame (60 total), and i added another sound file (from the library) to a certain frame. As expected, both sounds overlapp, so i decided to make a mute function... the problem is, i cant get it to apply only to the streaming audio, the function mutes all audio, and i cant use the variable mySound because the mute function needs to be on other keyframe to work...
Here's the code of the streaming audio:
var mySound:Sound = new Sound();
var myChannel:SoundChannel = new SoundChannel();
var lastPosition:Number = 0;// pause button
mySound.load(new URLRequest("http://trollfacequiz.16mb.com/MusicFiles/Goat%20Songs.mp3"));
//mySound.play();
SoundMixer.stopAll();
myChannel = mySound.play();
btn_mute.btn_pause.addEventListener(MouseEvent.CLICK, onClickPause);
btn_mute.btn_play.addEventListener(MouseEvent.CLICK, onClickPlay);
function onClickPause(e:MouseEvent):void
{
btn_mute.btn_pause.visible = false;
lastPosition = myChannel.position;
myChannel.stop();
}
function onClickPlay(e:MouseEvent):void
{
btn_mute.btn_pause.visible = true;
myChannel = mySound.play(lastPosition);
}
And the mute function:
function setVolume(vol){
var volTransform:SoundTransform = new SoundTransform();
volTransform.volume = vol;
SoundMixer.soundTransform = volTransform;
}
setVolume(0);

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 video player / attaching video(not camera) to NetStream in actionscript 3

I am new to actionscript, basically i am trying to stream video player but we can't use attachVideo in as3 so what can i use instead of attachVideo in following code? Im using flash builder/flex 4.6 . If you could suggest link/tutorial for streaming video player it would be great help. Thank you!
private function initOutStream():void
{ /* streamOut is NetStream to adobe cirrus ,
conn is making connection to adobe cirrus */
trace("initOutStream");
streamOut = new NetStream(conn,NetStream.DIRECT_CONNECTIONS);
streamOut.addEventListener(NetStatusEvent.NET_STATUS,streamStatus);
streamOut.publish("media");
// mp4 file from local machine
nc = new NetConnection();
nc.connect(null);
ns = new NetStream(nc);
ns.play("t.mp4");
ns.client = this;
var vid:Video = new Video;
vid.attachNetStream(ns);
// streaming vid to media server
streamOut.attachVideo(vid);
var streamOutClient:Object = new Object();
streamOutClient.onPeerConnect = function(farStream:NetStream):Boolean
{
return true;
}
}
error:
1061: Call to a possibly undefined method attachVideo through a reference with static type
This is a code i wrote lately for a business job. i hope it helps...
var vid:Video = new Video();
vid.width = 640; vid.height = 480;
addChild(vid);
var cnn:NetConnection = new NetConnection();
cnn.connect(null);
var ns:NetStream = new NetStream(cnn);
ns.play("t.mp4");
vid.attachNetStream(ns);
ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, error);
ns.addEventListener(NetStatusEvent.NET_STATUS, streamStatus);
function streamStatus(e:NetStatusEvent){
//trace(e.info.code);
if(e.info.code == "NetStream.Play.Stop"){
}
}
function error(e){
}

AS3 gotoAndPlay after video finishes playing

I have loaded a video wit this code
var video:Video = new Video(1440, 900);
addChild(video);
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
video.attachNetStream(ns);
var listener:Object = new Object();
listener.onMetaData = function(e:Object):void {};
ns.client = listener;
ns.play("introAPOK_blanco.f4v");
now I need to perform a "gotoAndPlay" to go to another frame or scene after the video finishes playing
Thanks!!
video.addEventListnere("complete", onPlayFinished);
function onPlayFinished(event:Event):void
{
//Video playback finished
}
UPDATE 1:
Check this tutorial http://www.adobe.com/devnet/flash/articles/flvplayback_programming.html
instead of "complete" use VideoEvent.COMPLETE