SampleDataEvent.SAMPLE_DATA 在 Flex 中永远不会触发?
麦克风.addEventListener(SampleDataEvent.SAMPLE_DATA,gotMicData); 事件gotMicData永远不会被触发..但是我尝试使用dispatchEvent,但这将返回null byteArray.. 然而类似的代码在 Flashcs5 中运行良好...
import flash.events.SampleDataEvent;
import flash.media.Microphone;
import flash.media.Sound;
import flash.utils.ByteArray;
[Bindable] private var microphoneList:Array;
protected var microphone:Microphone;
protected var isRecording:Boolean = false;
protected var soundRecording:ByteArray;
protected var soundOutput:Sound;
protected function setupMicrophoneList():void
{
microphoneList = Microphone.names;
}
protected function setupMicrophone():void
{
microphone = Microphone.getMicrophone(comboMicList.selectedIndex);
microphone.rate = 44;
}
protected function startMicRecording():void
{
isRecording = true;
soundRecording = new ByteArray();
microphone.addEventListener(SampleDataEvent.SAMPLE_DATA, gotMicData);
}
protected function stopMicRecording():void
{
isRecording = false;
microphone.removeEventListener(SampleDataEvent.SAMPLE_DATA, gotMicData);
}
private function gotMicData(micData:SampleDataEvent):void
{
soundRecording.writeBytes(micData.data);
}
protected function playbackData():void
{
soundRecording.position = 0;
soundOutput = new Sound();
soundOutput.addEventListener(SampleDataEvent.SAMPLE_DATA, playSound);
soundOutput.play();
}
private function playSound(soundOutput:SampleDataEvent):void
{
if (!soundRecording.bytesAvailable > 0)
return;
for (var i:int = 0; i < 8192; i++)
{
var sample:Number = 0;
if (soundRecording.bytesAvailable > 0)
sample = soundRecording.readFloat();
soundOutput.data.writeFloat(sample);
soundOutput.data.writeFloat(sample);
}
}
]]>
</mx:Script>
microphone.addEventListener(SampleDataEvent.SAMPLE_DATA, gotMicData);
the event gotMicData is never fired.. however i tried using dispatchEvent but that will return null byteArray..
However similar code works fine in Flashcs5...
import flash.events.SampleDataEvent;
import flash.media.Microphone;
import flash.media.Sound;
import flash.utils.ByteArray;
[Bindable] private var microphoneList:Array;
protected var microphone:Microphone;
protected var isRecording:Boolean = false;
protected var soundRecording:ByteArray;
protected var soundOutput:Sound;
protected function setupMicrophoneList():void
{
microphoneList = Microphone.names;
}
protected function setupMicrophone():void
{
microphone = Microphone.getMicrophone(comboMicList.selectedIndex);
microphone.rate = 44;
}
protected function startMicRecording():void
{
isRecording = true;
soundRecording = new ByteArray();
microphone.addEventListener(SampleDataEvent.SAMPLE_DATA, gotMicData);
}
protected function stopMicRecording():void
{
isRecording = false;
microphone.removeEventListener(SampleDataEvent.SAMPLE_DATA, gotMicData);
}
private function gotMicData(micData:SampleDataEvent):void
{
soundRecording.writeBytes(micData.data);
}
protected function playbackData():void
{
soundRecording.position = 0;
soundOutput = new Sound();
soundOutput.addEventListener(SampleDataEvent.SAMPLE_DATA, playSound);
soundOutput.play();
}
private function playSound(soundOutput:SampleDataEvent):void
{
if (!soundRecording.bytesAvailable > 0)
return;
for (var i:int = 0; i < 8192; i++)
{
var sample:Number = 0;
if (soundRecording.bytesAvailable > 0)
sample = soundRecording.readFloat();
soundOutput.data.writeFloat(sample);
soundOutput.data.writeFloat(sample);
}
}
]]>
</mx:Script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
安装 Flex Builder 还会将 sdk 3.2 设置为默认值,我发现您只需下载最新的 Flex sdk 并在 Flex Builder 中使用它..代码就可以正常工作..
Installing the Flex Builder will also set sdk 3.2 as default and I found that u just have to download the latest flex sdk and use it in flex builder.. and the code will work fine..
SampleDataEvent 是 Flash Player 10.1 的一项功能。在项目的 Flex 编译器属性中将播放器目标设置为 10.1 或更高,这样就可以了。
SampleDataEvent is a Flash player 10.1 feature. Set your player target to 10.1 or higher in the Flex Compiler properties for your project, and you should be good.
嘿,只是为了添加到此线程中,我遇到了类似的问题,直到我看到此博客上的评论:
http: //www.bytearray.org/?p=1858
基本上,您必须确保您的舞台足够大以容纳闪存安全设置窗口。
试图弄清楚这种美让我发疯。
Hey Just to add to this thread I was having a similar problem until I saw a comment on this blog :
http://www.bytearray.org/?p=1858
Basically you have to make sure your stage is big enough to accommodate the flash security settings window.
Drove me nuts trying to figure this beauty out.