AS3 SoundChannel/Sound HZ Limit for importing - actionscript-3

I have wav files that are at 1411kbs bit rate and varying frequencies. After I import them into the library and give them unique classes based on their frequency and other information (that is why I use getDefinitionByName below).
All of my wav files play fine in AS3 that are under 6000hz and 8000hz, however those tones don't play properly. However, they do play properly when clicking the Play icon when in Flash Adobe Animate.
I have stripped my code down to the bare essentials to see where the problem lies and still not working properly.
My question is, is there a problem with my code or does AS3/Flash have a limit on the frequency it can play?
var mySound:Sound = new Sound();
var myChannel:SoundChannel = new SoundChannel();
btn.addEventListener(MouseEvent.CLICK, function(){
var sound_class = "L6000_0";
var soundTX:SoundTransform = myChannel.soundTransform;
soundTX.leftToLeft = 1;
soundTX.leftToRight = 0;
soundTX.volume = 1;
soundTX.rightToRight = 0;
soundTX.rightToLeft = 0;
var sclass:Class = getDefinitionByName(sound_class) as Class;
var mySound:Sound = new sclass;
myChannel.stop();
myChannel = mySound.play();
myChannel.soundTransform = soundTX;
});

It is not the scripting problem, I think. By default Flash exports sounds at very low bitrate and quality. Go to each sound properties to set the export settings or, alternately, in File > Publish Settings screen there's an option about exporting sounds.

Related

Got my external NetStream working - but how to load an .flv from my library?

How do I load an .flv (lets call it "library.flv") sitting in my (internal) Flash library into my Netstream?
I can easily load external .flv's with the below, but I need to load the .flv from my library
//Creating the video object
var ADFvideo = new Video(110,180);
videoContainer.addChild(ADFvideo);
ADFvideo.x = 0;
ADFvideo.y = 0;
//Loading the flv into the video object
var ADFnc:NetConnection = new NetConnection();
ADFnc.connect(null);
var ADFns:NetStream = new NetStream(ADFnc);
ADFvideo.attachNetStream(ADFns);
//Handling metaData (it arrives as the video starts playing, so it is the pefect time to fire the first event);
var ADFcustomClient:Object = new Object();
ADFcustomClient.onMetaData = ADFmetaDataHandler;
ADFns.client = ADFcustomClient;
var ADFinfoObj:Object;
function ADFmetaDataHandler(ADFinfo:Object):void
{
//meta stuff
}
ADFns.play("files/external.flv"); /* current way of loading the external .flv */
ADFns.addEventListener(NetStatusEvent.NET_STATUS, statusChanged);
function statusChanged(stats:NetStatusEvent)
{
//event changes
}
I don't think you can use NetStream with an embedded flv video. When you import the video to your library, you will have the option to convert it to a movieclip or to keep it as a simple video that will sit on the timeline. For the later option, you can't create an AS Linkage. It is not recommended for longer clip as you will experience syncronisation issue, playback problem and pre-loading issues.
You could try this adjustment of your posted code as a starting point.. Tested using 3-second video (H.263 / Sorenson) of 1280 width by 720 height with 44100hz 128 MP3 sound and there was no "..experiencing sluggish behaviour" on my side with a crappy testing machine.
When the video ends you need to use your function statusChanged(stats:NetStatusEvent) to handle what happens next (I've edited the code to do constant replays as example)
Anyway this code means the final compiled SWF and FLV exist as one package. So a 200kb FLV will add +200kb to the output SWF size. Just bear in mind especially with large / multiple FLV embeds.
//// Specify embed item and create Class to store such item
[ Embed(source = "yourFileName.flv", mimeType = "application/octet-stream") ]
var bytes_FLV : Class;
//// End embedded item setup
//create bytes for NStream from embedded item
var file_BA:ByteArray = new bytes_FLV();
//Creating the video object
var ADFvideo = new Video(110,180);
videoContainer.addChild(ADFvideo);
ADFvideo.x = 0;
ADFvideo.y = 0;
//Loading the flv into the video object
var ADFnc:NetConnection = new NetConnection();
ADFnc.connect(null);
var ADFns:NetStream = new NetStream(ADFnc);
ADFvideo.attachNetStream(ADFns);
//Handling metaData (it arrives as the video starts playing, so it is the pefect time to fire the first event);
var ADFcustomClient:Object = new Object();
ADFcustomClient.onMetaData = ADFmetaDataHandler;
ADFns.client = ADFcustomClient;
var ADFinfoObj:Object;
function ADFmetaDataHandler(ADFinfo:Object):void
{
//meta stuff
}
///ADFns.play("files/external.flv"); /* current way of loading the external .flv */
//Send file_BA to NStream for playback..
ADFns.play(null);
ADFns.appendBytesAction(NetStreamAppendBytesAction.RESET_BEGIN);
ADFns.appendBytes(file_BA);
ADFns.addEventListener(NetStatusEvent.NET_STATUS, statusChanged);
function statusChanged(stats:NetStatusEvent)
{
//event changes
//trace("NetStream Status : " + stats.info.code);
if (stats.info.code == "NetStream.Buffer.Empty")
{
//Buffer.Empty = video has ended..
ADFns.appendBytesAction(NetStreamAppendBytesAction.RESET_BEGIN);
ADFns.appendBytes(file_BA);
}
}

How to play a video while it is loading in Flash AS3?

I have a problem in Flash with AS3 to playing a video mp4, this is a H.264 video with AAC, I try to play video while it is loading as any web site, but my code doesn't work, I have two codes:
Using FLVPlayback:
var par:Object = LoaderInfo(this.root.loaderInfo).parameters;
//vidRepFla is my FLVPlayback
vidRepFla.addEventListener(VideoEvent.READY,vid_ready);
vidRepFla.addEventListener(VideoProgressEvent.PROGRESS,vid_progress);
vidRepFla.isLive = true;
vidRepFla.bufferTime = 1;
vidRepFla.play(par.source);
function vid_ready(e:VideoEvent):void{
trace('Playing!');
vidRepFla.play();
}
function vid_progress(e:VideoProgressEvent){
trace(e.bytesLoaded);
}
Using NetStream:
var par:Object = LoaderInfo(this.root.loaderInfo).parameters;
var video:Video;
var connect_nc:NetConnection = new NetConnection();
connect_nc.connect(null);
var stream_ns:NetStream = new NetStream(connect_nc);
stream_ns.client = this;
video = new Video();
addChild(video);
stream_ns.bufferTime = 1;
video.attachNetStream(stream_ns);
stream_ns.play(par.source);
Do you know if I need something more or if this type video don't work the bufferTime?
Thanks!
I work with Netstream and use a different method. I did notice something on the Adobe documentation for this. I read that the bufferTime setting Only works on flv files, this could be the problem since you are using mp4.
More information here:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/NetStream.html

embed sound so that when publish we do not have to include it in the same folder as the swf file

i have a flash animation with sound that have play,pause,stop,go to start and go to end button.
when i publish it i have to include the mp3 file along with the swf file.
how do i do to get the swf file alone in order to play the whole thing?
i am using flash cs 3 and actionscript 3.0
here is my codes:
var mySound:Sound = new Sound();
var myChannel:SoundChannel = new SoundChannel();
var lastPosition:Number = 0;
var soundIsPlaying:Boolean = true;
mySound.load(new URLRequest("saloma.mp3"));
myChannel = mySound.play();
all those buttons will go to functions,
go.addEventListener(MouseEvent.CLICK,govid);
function govid(event:MouseEvent):void{
play();
if(!soundIsPlaying){
myChannel = mySound.play(lastPosition);
soundIsPlaying = true;
}
}
i am also using scenes to navigate them,
gte.addEventListener(MouseEvent.CLICK,gotoend);
function gotoend(event:MouseEvent):void{
gotoAndStop(1,"ending");
}
thank you :)
I would have written the answer, but this has been answered already...
First, in your library, set the class linkage of a sound file by right clicking, selecting properties and editing the Class field in the Linkage section. In this example it will be Class:FogHorn
import flash.utils.getDefinitionByName;
var SoundClass:Class = getDefinitionByName("FogHorn") as Class;
var newSound:Sound = new SoundClass();
newSound.play()
source: #Allan in Actionscript 3: playing sound from library with name from string
import your mp3 file to your library
select your mp3 file in the library and right click on it
a pop-up window will appear (click on advanced if it is not yet clicked)
under the actionscript linkage, you will see class field, type "sound1" for example (no 5. quotations, this can be any other name aside from sound1)
instead of var mySound:Sound = new Sound(); this code, type
var mySound:Sound = new sound1(); //sound1 is the name of your linkage/class
You don't need this codes anymore. You need to omit your myChannel variable.
mySound.load(new URLRequest("saloma.mp3"));
myChannel = mySound.play();
To play the sound, simply type
mySound.play();

Play MP3 in AIR app for iOS and Android

I was wondering if someone could shed some light on the best method to embed, select and play audio files in an AIR app built for iOS and Android?
I have an app where a user can select a file to play from a list of 10 audio files. These are selected when a slider moves left or right.
I currently would create 10 individual embed snippets and classes
[Embed(source="assets/audio/file1.mp3)]
public static const file1:Class;
[Embed(source="assets/audio/file2.mp3)]
public static const file2:Class;
...
And then in the app initialise each class so I can reference them. Then simply call
file1.play();
Issue is this only plays the sound once where I would like the sound to look until the user selects another sound.
I guess a couple of questions:
1. Is having 10 embed/classes the best way to handle 10 different MP3 files?
2. How would I loop the MP3 seamlessly
Thanks
You stored Array or Vector mp3 files URL which user selected. and playing mp3 filed ended. load next URL from Array, Vector.
var sound:Sound = new Sound();
var soundChannel:SoundChannel;
var currentIndex:int = 0;
var mp3List:Vector.<String> = new Vector.<String>();
//only stored user selected mp3 url
sound.addEventListener(Event.COMPLETE, onMp3LoadComplete);
sound.load(mp3List[currentIndex]);
function onMp3LoadComplete(e:Event):void
{
sound.removeEventListener(Event.COMPLETE, onMp3LoadComplete);
soundChannel = sound.play();
soundChannel.addEventListener(Event.SOUND_COMPLETE, onSoundChannelSoundComplete);
}
function onSoundChannelSoundComplete(e:Event):void
{
e.currentTarget.removeEventListener(Event.SOUND_COMPLETE, onSoundChannelSoundComplete);
currentIndex++;
if(currentIndex==mp3List.length) currentIndex = 0;
sound.load(mp3List[currentIndex]);
soundChannel = sound.play();
sound.addEventListener(Event.COMPLETE, onMp3LoadComplete);
}

Flash AS3 animation not running in IE9

I've got five Flash animations, that use AS3 computeSpectrum to create video animations for some of my songs.
Tested in Chrome, Firefox, Opera, and Safari just fine. Tested in IE7 and IE8 just fine. Tested in IE9, the flash player opens, but the music doesn't play, and the animations don't even start. This ONLY occurs in IE9.
Web page here: http://seanmurphy.co.cc/index4.html
The animations are under the music tab (bottom tab, main screen).
Does anyone have a line on what the heck is going on? I've made sure the Flash player is up-to-date (like I said, actually uninstalled IE9, back to IE8 and worked fine). I've made sure the linked mp3 files are in both the root folder and the attached audio folder (just in case). I've researched this all over, but no one seems to have this same problem.
Flash AS3 code below:
var url:String = "SubwayGirl.mp3";
var request:URLRequest = new URLRequest(url);
import flash.filters.*;
import fl.motion.Color;
var myBlur:BlurFilter = new BlurFilter();
myBlur.quality = 10;
myBlur.blurX = 0;
myBlur.blurY = 6;
var s:Sound = new Sound();
s.addEventListener(Event.COMPLETE, completeHandler);
s.load(request);
var song:SoundChannel = s.play();
song.addEventListener(Event.SOUND_COMPLETE, soundCompleteHandler);
var ba:ByteArray = new ByteArray();
var gr:Sprite = new Sprite();
gr.x = 150;
gr.y = 575;
addChild(gr);
var time:Timer = new Timer(.0001);
time.addEventListener(TimerEvent.TIMER, timerHandler);
time.start();
function completeHandler(event:Event):void {
//event.target.play();
};
function randomNumber(low:Number=0, high:Number=1):Number
{
return Math.floor(Math.random() * (1+high-low)) + low;
}
function soundCompleteHandler(event:Event):void {
time.stop();
};
function timerHandler(event:TimerEvent):void {
SoundMixer.computeSpectrum(ba, true);
var i:int;
gr.graphics.clear();
gr.graphics.lineStyle(1, 0xffffff);
myBlur.blurX = randomNumber(1, 5);
myBlur.blurY = randomNumber(1, 25);
myBlur.quality = randomNumber(1, 100);
gr.filters = [myBlur];
gr.graphics.beginFill(0xffffff);
gr.graphics.moveTo(10, 5);
var w:uint = 20;
for (i=0; i<500; i+=w) {
var t:Number = ba.readFloat();
var n:Number = (t * 100);
gr.graphics.drawCircle(w, -i, -n);
var yy = i * (t+210);
var place = yy.toString(16).toUpperCase();
while(place.length < 6) {
place = place+"0";
}
place = "0x" + place;
var myColor:ColorTransform = gr.transform.colorTransform;
myColor.color = 0xC941D0;
gr.transform.colorTransform = myColor;
};
};
Anyone with a hint on this? I've spent hours researching this with no resolution.
Any further info needed will be ASAPed over. Thanks.
EDIT: Okay, here's the scoop: I've got Flash animations playing at seanmurphy.co.cc/soundTest1.html in IE9. That is, they play if the browser cache is emptied, and you load the page once. If you reload the page, or go back to the page after visiting another page, the animations and music WON'T play, until you empty the cache again.
As well, I've copied the Flash object and embed codes over to a temporary index file at seanmurphy.co.cc/index6.html, but they won't play even with the browser cache emptied.
As you might think, this is driving me friggin' nuts! Does ANYONE have an explanation for the idiotic crap that IE is pulling here? I'd really really like to put this thing to bed. Thanks!
It may have something to do with the Security Sandbox violation:
SecurityError: Error #2121: Security sandbox violation:
SoundMixer.computeSpectrum: http://seanmurphy.co.cc/audio/IndianSummer-amped.swf
cannot access http://seanmurphy.co.cc/audio/SubwayGirl.swf.
This may be worked around by calling Security.allowDomain.
at flash.media::SoundMixer$/computeSpectrum()
at IndianSummer_fla::MainTimeline/timerHandler()
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick()