Flash Actionscript 3 - sound seeking/playing - actionscript-3

I have an audio file which is 4 hours long. I created a standart player to manage my needs - works fine, but you dont seek more than 12180000 miliseconds in position count player stops. If you position the sound to play 12100000 (few seconds earlyear) - plays fine and if it countinues to play without changing the position by code, it is good till the end. I dont get any errors, or any kind of information regarding this kind of issue.
soundChannel = sound.play(12180000); // DOES NOT PLAY, NO ERRORS
soundChannel = sound.play(12100000); // PLAYS FINE, AND CONTINUES TO PLAY TILL THE END
Sound is fully loaded, before playing.
So anybody have any ideas?

this is interesting... I cannot get it to play past 12173943 milliseconds. For me, it works up that that exact number, but anything after that, it won't play. My guess is flash allots a certain amount of memory for sounds and that number right there calculates to the maximum amount of memory allotted for that file. Hopefully someone else can chime in. I am using the MP3 provided by Rummer and this was my test code
import flash.media.*;
import flash.events.*;
import flash.net.*;
var channel:SoundChannel = new SoundChannel();
var sound:Sound = new Sound();
sound.load(new URLRequest("podcast.mp3"));
sound.addEventListener(Event.COMPLETE, soundLoaded);
sound.addEventListener(IOErrorEvent.IO_ERROR, onError);
function soundLoaded(e:Event):void
{
channel = sound.play(12173943);
}
function onError(e:IOErrorEvent):void
{
trace(e);
}
I'm using Flash CS5.5 and exporting for flash 10.2. I would highly consider splitting your mp3s into sections. The first time my SWF loaded, flash hung for a good 10 seconds before it played because of how large the mp3 is.
=============== AS2 version that works
var my_sound:Sound = new Sound();
my_sound.onLoad = function(success:Boolean)
{
if (success)
{
my_sound.start(12180);
}
};
my_sound.loadSound("podcast.mp3", true);

Related

Flash player stuck at Frame 1 after calling a function

I'm working in a flash CS6 and I'm having a trouble: After calling a function, player freezes at frame 1. This not happend during Ctrl+ENTER preview, but when I play the .swf file published (using flash player or opening it on a web browser, doesn't matter) is when the problem begin.
This is the code:
import flash.display.MovieClip;
var code:int = 0
var temp:int = 0;
var _xmlURL:String = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid=368335%20and%20u=%27c%27";
var _xmlData:XML;
function loadXML(xmlURL:String):void {
var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest(_xmlURL);
loader.load(request);
loader.addEventListener(Event.COMPLETE, loadData);
}
function loadData(event:Event):void{
_xmlData = new XML(event.currentTarget.data);
var dataG:XMLList = _xmlData.results.channel.item.elements();
code = dataG[5].#code;
temp = dataG[5].#temp;
trace(code);
trace(temp);
}
loadXML(_xmlURL);
I'm not used to use as3, I don't know if I'm using it right.
As you can see, the code reads an external xml file using "URLLoader" and its method ".load".
Thanks for your help.
BTW, I've already tried to play the published ".swf" file in other PCs (xp, seven, 8), one of them with Windows recently installed (seven).
Most likely (because you're loading in resources from the internet, and it works when you test), this has to do with the security settings of your application.
Go to your publish settings file -> publish settings.
You'll see a drop down labelled Local playback security. Ensure this is set to access network only and not the default acess local only.
This hangs up a lot of people when they first start using flash.
It's always good practice too, to listen not just for the COMPLETE event on your loaders, but also for error events such as:
loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandlerFunction);
loader.addEventListener(IOErrorEvent.NETWORK_ERROR, ioErrorHandlerFunction);
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandlerFunction);
In your case, it's probably throwing a security error.

create (webcam capture like youtube) in my website

I have a website working the same as youtube. At this moment I am trying to create a video image captured by WEBCAM.
The video image should be saved on my computer (by FLV format) first and then if the user is satisfied, he or she can upload it on the server
I am trying to use Actionscript3 in Adobe flash CS5 and Flash media server4
1- How can I do that?
2- Is the flash media server needed?
Please pay attention that we would like to allow the user to save video on his/her computer and then be able to uploaded to the server.
Many thanks.
Assuming the computer can take the overhead of doing the encoding on the fly (or has enough memory to buffer the data then can run the data through an encoding process) then the library mentioned in the SO answer here should work:
Encode video from any format to .flv format in AS3
I believe the Flash media server would only really be necessary in this case for broadcast.
Pseudocode example
private var cam:Camera;
public function Whatever()
{
//In constructor
addEventListener(Event.ENTER_FRAME, grabFrame);
cam = Camera.getCamera();
if (cam != null)
{
var vid:Video = new Video(cam.width, cam.height);
vid.attachCamera(cam);
addChild(vid);
}
}
private function grabFrame(event:Event):void
{
var bd:BitmapData = new BitmapData(cam.width, cam.height)
bd.draw(vid);
//now the BitmapData has a frame of the video, at this point you also
//would want to capture the audio then use the FLV class in the library
}
You can also check out using Red5 as an alternative open source video stream recorder.
http://distriqt.com/post/493
Cheers

Red5 server only records first few seconds of RTMP video feed from AIR

I am testing a new installation of Red5 server using the oflaDemo that is installed. I am wanting to publish a live video feed to be recorded to a file. This seems to work ok except for the fact that only a fraction of the video feed is ever recorded. Only the first frame for videos of around 30 seconds ever seems to be available to play back and only a few seconds of video is recorded for longer (~10 minutes) of video.
What could cause Red5 out of the box to only record a few seconds of video?
------------ Heres a code snippet -------------------------------------------------------------------------------------------
nc = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
nc.connect("rtmp://myurl");
nc.client = this;
ns_out = new NetStream( nc );
ns_out.attachCamera( cam )
protected function onNetStatus(event:NetStatusEvent):void
{
switch(event.info.code)
{
case "NetConnection.Connect.Success":
ns_out.publish(_filename, "record");
break;
}
}
It seems to me this is a bug in the latest version of Red5. I have the same issue with an audio recorder app. Although I used to record streams with no problems in older versions of Red5.

Why does URLStream complete event get dispatched when the file is not finished loading?

I'm writing an AIR kiosk app that every night connects to a WordPress server, gets a JSON file with paths to all the content, and then downloads that content and saves it to the kiosk hard drive.
There's several hundred files (jpg, png, f4v, xml) and most of them download/save with no problems. However, there are two f4v files that never get downloaded completely. The complete event does get dispatched, but if I compare the bytesTotal (from the progress event) vs bytesAvailable (from the complete event) they don't match up; bytesTotal is larger. The bytesTotal (from the progress event) matches the bytes on the server.
The bytesLoaded in the progress event never increases to the point that it matches the bytesTotal either so I can't rely on the progress event either. This seems to happen on the same two videos every time. The videos are not very large, one is 13MB and the other is 46MB. I have larger videos that download without any problems.
EDIT: After rebooting my computer, the two videos now finish downloading but I'm getting the same problem with a 300kb png file.
If I paste the url into Firefox it downloads correctly. I've also written a simple c# app to download the files and it is able to download them with no problems, so it appears to be a problem with Flash/AIR.
EDIT: here's a simpler version of the code, this is from a test project and it's the only code (the url is on our local network so you won't be able to download the file yourself):
package {
import flash.display.Sprite;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.net.URLRequest;
import flash.net.URLStream;
[SWF(backgroundColor="#000000", frameRate="24", width="640", height="480")]
public class Test extends Sprite {
private var fileSize:Number;
private var stream : URLStream;
private var url:String = "http://192.168.150.219/wordpress2/wp-content/uploads/2012/12/John-Butler-clip1.f4v";
public function Test() {
if (stage)
init();
else
this.addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event=null):void {
this.removeEventListener(Event.ADDED_TO_STAGE, init);
stream = new URLStream();
stream.addEventListener(ProgressEvent.PROGRESS, onLoadProgress);
stream.addEventListener(Event.COMPLETE, onLoadComplete);
stream.load(new URLRequest(url));
}
private function onLoadProgress(event:ProgressEvent):void {
fileSize = event.bytesTotal;
var percent:Number = event.bytesLoaded / event.bytesTotal * 100;
trace(percent + "%"); // this never gets to 100%
}
private function onLoadComplete(event:Event):void {
trace("loaded", stream.bytesAvailable, "of", fileSize);
// outputs "loaded 13182905 of 13184365"
// so why is it "complete" when it isn't fully downloaded?
}
}
}
Don't compare to bytesAvailable, use length instead. BytesAvailable is actually ByteArray.length - ByteArray.position. So if the position within the ByteArray has moved away from index 0, the bytesAvailable value will decrease. Length will always be the total number of bytes within the array.
Try comparing using length and see if this makes any difference. I don't have time to sift through your code to see if you are changing position at any point (either purposefully or accidentally; you can do it in more ways than one), so that's the best I can offer right now.
If anyone else has the same problem like I did. It turned out to be a caching problem which is present in AIR as well so a timestamp added to the request solves this: http://www.newtonflash.com/blog/as3/prevent-xml-caching-problem/#comment-43
{
var xmlPath:String="replaceYourXMLPathHere.xml"
var urlReq:URLRequest = new URLRequest(xmlPath+"?time=" + new Date().getTime());
}
Your answer is in your question.
Normal URLs (files) - to this server this is a block of data. Once the server delivers the 'block of data' the delivery process is considered 'COMPLETE'. In this case if a file is 100kb, once the 100kb is received - Flash considers this as 'COMPLETE'.
URLStream - to the server this is [TWO] blocks of data (very simple way to look at it). The server will first serve the CONNECTION to the stream... then serve the STREAM DATA. This is handled in Flash just as its described.
Flash will consider the loading of the CONNECTION as 'COMPLETE', and NEVER check if the STREAM data is loaded - thats up to your server. In any streams you should actually check the [load progress] event and read each byte of data as it comes in... then construct as required.

AS3-ID3 event in a web radio

I'm building an online radio player using the AS3 code below:
private var soundChannel:SoundChannel;
private var stationUrl:String = "h t t p : / /205.188.215.230:8002/";
sound = new Sound();
sound.addEventListener(Event.ID3, onID3Change);
sound.load(new URLRequest(stationUrl));
soundChannel = sound.play();
private function onID3Change(e:Event):void
{
....
}
the sound plays successfully, but the problem is that the ID3 event is never triggered!
Does anyone know how to solve this?
ID3 doesn't exist in internet radio streams like this one. I am assuming you're talking about a SHOUTcast/IceCast stream.
For that, you need to implement the icy metadata protocol. For Flash, this is generally just done externally.
See this reference: http://www.smackfu.com/stuff/programming/shoutcast.html
Basically, you send icy-metadata: 1 in the headers of your GET request. The server then inserts metadata right into the middle of the stream, which you pull out before sending the data on to whatever is playing the stream. I'm not sure if this is even possible in Flash, but it certainly is possible to do this in PHP (or any server-side language really) and have your Flash application make a request to your PHP script to get that metadata.