I'm trying to achieve seamless looping of an MP4 (or M4A to be more specific) sound. The usual method of loading, playing to the end, and then seeking to position zero causes a small delay (less than a second) before the second playback begins.
So now I'm trying to preload the sound data and then use NetStream.appendBytes() to append the whole sound data at the end of the original sound, expecting the sound to repeat once. But first, I want to be able to play the sound just once using the appendBytes() method. Here is the code I wrote that doesn't give any errors but doesn't play a sound either:
var data:ByteArray = new SoundData; // SoundData class contains the embedded M4A file data
var connection: NetConnection = new NetConnection();
connection.connect(null);
var stream: NetStream = new NetStream(connection);
stream.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
stream.client = {};
function onNetStatus(event:NetStatusEvent): void {
trace(event.info.code, stream.time, stream.bytesLoaded, stream.bytesTotal);
}
stream.play(null);
stream.appendBytesAction(NetStreamAppendBytesAction.RESET_BEGIN);
stream.appendBytes(data);
Am I using appendBytes() correctly?
I ended up using a hack for achieving apparent seamless looping: loading two sound files through NetStream, playing one, and 100ms before its end, starting to play the other.
Related
After recording a sound and converting it into wav...
var enco:WaveEncoder=new WaveEncoder();
var o:ByteArray=enco.encode(soundO,1,16,44100);
I pass it to ShineMP3Encoder
_mp3_encoder = new ShineMP3Encoder(o);
_mp3_encoder.addEventListener(Event.COMPLETE, onMP3EncoderComplete, false, 0, true);
_mp3_encoder.start();
onMP3EncoderComplete has two vars
var mp3:ByteArray = _mp3_encoder.mp3Data;
var wav:ByteArray = _mp3_encoder.wavData;
wav audio is normal, but mp3 almost always (99%) has a clicking sound when audio begins.
Here's a picture from SoundForge app.
We can see these two files are identical, but mp3 has a clicking sound at the beginning.
Is it my system/hardware/compiler problem or it's something else?
btw I tried some online swf example of ShineMP3Encoder and it has same issue. So probably that's not my compiler problem
I know that we can not record/Access anything out of flash player, because of it's security sandbox.
Instead We can record the video while streaming it to server.
like
netStream.publish("YourFileName.flv","record");
But in recorde file, I will get only a video file Published by webcam to server and i want to record entire session.
Is there any way to record it locally, or Can i record the window ??
p.s. : I am not trying to access anything outside of flash player.
Thanks in advance...
ok, so you can record the entire contents of the swf like this:
first, create a container object (anything that extends DisplayObject which implements IBitmapDrawable) then place everything that you want to capture (video view and everything else in your "session") then using an ENTER_FRAME event or Timer (preferable to control capture fps), draw the container to a BitmapData using BitmapData.draw(container). Pass that BitmapData to the FLV encode library found here using it's addFrame() method (docs and examples come with that library... super easy) and that's it! When you are done, you will have an flv video containing a frame by frame "screen capture" of what was going on in your swf! Just make sure EVERYTHING is in the container! That lib also accepts captured audio too if you want.
private function startCapturing():void{
flvEncoder.start(); // see the libs docs and examples
var timer:Timer = new Timer(1000/15); //capture at 15 fps
timer.addEventListener(TimerEvent.Timer, onTimer);
timer.start();
}
private function onTimer(event:TimerEvent):void{
var screenCap:BitmapData = new BitmapData(container.width, container.height);
screenCap.draw(container);
flvEncoder.addFrame(screenCap); // see the libs docs and examples
}
I have video streaming from the server, and later on I want to add another one just side by side. thats all good, I done that. Now my problem comes when i want to remove video. I manage to remove it from display, but I can hear that video is still playing in the background. So how do I can stop streaming that video?
Here is my code for setting up the video:
ns = new NetStream(connection);
ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
ns.play(item[1].toString() + ".flv");
video = new Video();
video.attachNetStream( ns );
video.width = 160;
video.height = 120;
videoWrapper = new UIComponent();
videoWrapper.addChild( video );
videos.addElement( videoWrapper );
and here is for removing
videos.removeElement(myVideos[p][1]); // myVideos[p][1] is a reference of videoWrapper
You can drop the connection by calling video.attachNetStream(null), or close the stream with ns.close();
It's probably best to do both.
On a normal video object, do not call attachNetStream(null), because AS3, later will not let clear the last video frame from the video with .clear()
Looks like a bug.
Use ns.close(), then use vid.clear(), so that the video object can be transparent again.
On StageVideo, this is different:
You can call vid.attachNetStream(null), it will remove the last frame too from the stagevideo.
Be careful, it will not stop the playing itself. You have to call ns.close();
I'm building a webcam recording app in CS5 and I'm having some seemingly random issues with the recorded flv. Currently I'm publishing a stream to Wowza Media Server using the standard _netstream.publish("movieName", "record") command. Everything regarding this works fine and I can play the file back but sometimes there's a 3 to 4 second pause at the beginning or end of the video. There will be a still frame and the time will sit at 0 and then snap to 4. I've explored bandwidth options and I've turned the resolution and quality down considerably and it doesn't seem to have any effect and the rest of the video will play back smoothly. Here are my current camera and mic settings.
_cam.setMode(160, 120, 30, false);
_cam.setQuality(0, 88);
_cam.setKeyFrameInterval(30);
_mic.rate = 11;
I'm also flushing the buffer before closing out the publish stream
_netstream.publish('null');
Could there be something going on with camera initialization/deactivation that causes the lag?
Any help would be greatly appreciated. Let me know if you need more details
I believe this has something to do with the way that the Flash plugin itself initializes and displays the camera.
If you set up a simple test to try setting and unsetting the video stream:
var cam:Camera = Camera.getCamera();
var webcam:Video = new Video(500, 375);
addChild(webcam);
var isPaused:Boolean = false;
function showWebcam():void {
if (!isPaused) {
cam = null;
} else {
cam = Camera.getCamera();
}
webcam.attachCamera(cam);
isPaused = !isPaused;
}
pausingButton.addEventListener(MouseEvent.CLICK, showWebcam);
You'll notice a definite pause as it switches between the two states.
From what I've seen, every time I call attachCamera() with a video object, there is a noticeable pause of the Flash Player itself (including all tweens, interactions, everything) when the method is called, even if the object I'm attaching is null.
Four seconds seems like an excessive lag, but I have noticed that the larger the input/video render and with smoothing = true set on the video object can affect the length of the delay.
As for a solution; I'm not sure if there is one achievable via pure Actionscript, since the delay appears to be down to how the Flash Player itself initializes and renders the live video object.
I am trying to stop the audio of the video swf and I can't get it to stop. Here is my code for loading the file:
var myLoader:Loader= new Loader();
myLoader.x=420;
myLoader.y=200;
// boolean variable set for use below in our function
var screenCheck:Boolean = false;
//These three linces keep stafe elements the same size, so they don't distort
var swfStage:Stage = this.stage;
video_btn.addEventListener(MouseEvent.CLICK,contentvideo);
function contentvideo (event:MouseEvent):void{
myLoader.load(new URLRequest("prevideo.swf"));
addChild(myLoader);
movie_btn.stop();
movie_btn.visible=false;
}
Now I have other functions that load different URLRequest and when they are loading, the audio keeps playing. Do I have to add a line of code to them? I also have an MP3 player and tried SoundMixer.stopAll(). I still need the mp3 player to keep playing.
I'm not familiar with what you're doing but just looking at the code and given the problem you're experiencing I wonder if that
addChild(myLoader);
has anything to do with it. It seems like the kind of thing that could easily create multiple child objects which is why you continue to experience the sound play back. Is there a removeChild[0] option or something?
A shot in the dark I know but I thought I'd offer the possibility anyway.