Adobe Air ile uygulama denemelerim olmuştu, uzman değilim bu konuda ama...
"Java Kodu eklemek istiyorum" bu kısmı anlamadım ? Pek alakada kuramadım...Tam olarak yapmak istediğiniz nedir ?
Air ve Java ayrı platformlar olduğu için alaka kuramadığımdan sordum , ama şimdi konuyu anlatınca daha netleşti olay.
Java bilgin belli bir seviyede ise, AS3 sana pekte zor gelmeyecektir diye tahmin ediyorum, AS3'ü OOP üzerinden incelersen sanırım söylemeye çalıştığım şeyi daha net anlarsın.
AS3 ile ilgili genel önyargı; sadece frame'lere kod yazmak olarak görüldüğü için, insanlara antipatik gelebiliyor.
Yani konu air de uyglama geliştirmekse AS3 bilgi artışı zaten kaçınılmaz.
Konuya dönersek, şöyle bir link buldum belki bir fikir verebilir...
link
package {
import flash.display.Sprite;
import flash.media.Microphone;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.events.MouseEvent;
import flash.events.SampleDataEvent;
import flash.utils.ByteArray;
import flash.events.Event;
import flash.media.SoundMixer;
import flash.media.AudioPlaybackMode;
public class RecTest extends Sprite {
var mic:Microphone;
var s:Sound;
var sc:SoundChannel;
var nowRecording:Boolean = false;
var nowPlaying:Boolean = false;
var recordedBytes:ByteArray;
public function RecTest() {
SoundMixer.audioPlaybackMode = AudioPlaybackMode.MEDIA;
mic = Microphone.getMicrophone();
mic.rate = 44;
mic.gain = 70;
mic.setSilenceLevel(0);
s = new Sound();
recordedBytes = new ByteArray();
recorder.addEventListener(MouseEvent.CLICK, record);
player.addEventListener(MouseEvent.CLICK, playBack);
}
function record(e:MouseEvent) {
if (!nowRecording) {
trace("recording");
recordedBytes.clear();
mic.addEventListener(SampleDataEvent.SAMPLE_DATA, getMicAudio);
nowRecording = true;
} else {
trace("recording stopped");
mic.removeEventListener(SampleDataEvent.SAMPLE_DATA, getMicAudio);
nowRecording = false;
}
}
function getMicAudio(e:SampleDataEvent) {
recordedBytes.writeBytes(e.data);
}
function playBack(e:MouseEvent) {
if (!nowPlaying) {
trace("playing");
recordedBytes.position = 0;
s.addEventListener(SampleDataEvent.SAMPLE_DATA, playAudio);
sc = s.play();
sc.addEventListener(Event.SOUND_COMPLETE, stopPlayback, false, 0, true);
nowPlaying = true;
} else {
sc.stop();
stopPlayback();
}
}
function stopPlayback(e:Event=null) {
trace("playing stopped");
s.removeEventListener(SampleDataEvent.SAMPLE_DATA, playAudio);
nowPlaying = false;
}
function playAudio(e:SampleDataEvent) {
for (var i:int = 0; i < 8092 && recordedBytes.bytesAvailable > 0; i++) {
var sample:Number = recordedBytes.readFloat();
e.data.writeFloat(sample);
e.data.writeFloat(sample);
}
}
}
}
package {
import flash.display.Sprite;
import flash.media.Microphone;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.events.MouseEvent;
import flash.events.SampleDataEvent;
import flash.utils.ByteArray;
import flash.events.Event;
import flash.media.SoundMixer;
import flash.media.AudioPlaybackMode;
public class RecTest extends Sprite {
var mic:Microphone;
var s:Sound;
var sc:SoundChannel;
var nowRecording:Boolean = false;
var nowPlaying:Boolean = false;
var recordedBytes:ByteArray;
public function RecTest() {
SoundMixer.audioPlaybackMode = AudioPlaybackMode.MEDIA;
mic = Microphone.getMicrophone();
mic.rate = 44;
mic.gain = 70;
mic.setSilenceLevel(0);
s = new Sound();
recordedBytes = new ByteArray();
recorder.addEventListener(MouseEvent.CLICK, record);
player.addEventListener(MouseEvent.CLICK, playBack);
}
function record(e:MouseEvent) {
if (!nowRecording) {
trace("recording");
recordedBytes.clear();
mic.addEventListener(SampleDataEvent.SAMPLE_DATA, getMicAudio);
nowRecording = true;
} else {
trace("recording stopped");
mic.removeEventListener(SampleDataEvent.SAMPLE_DATA, getMicAudio);
nowRecording = false;
}
}
function getMicAudio(e:SampleDataEvent) {
recordedBytes.writeBytes(e.data);
}
function playBack(e:MouseEvent) {
if (!nowPlaying) {
trace("playing");
recordedBytes.position = 0;
s.addEventListener(SampleDataEvent.SAMPLE_DATA, playAudio);
sc = s.play();
sc.addEventListener(Event.SOUND_COMPLETE, stopPlayback, false, 0, true);
nowPlaying = true;
} else {
sc.stop();
stopPlayback();
}
}
function stopPlayback(e:Event=null) {
trace("playing stopped");
s.removeEventListener(SampleDataEvent.SAMPLE_DATA, playAudio);
nowPlaying = false;
}
function playAudio(e:SampleDataEvent) {
for (var i:int = 0; i < 8092 && recordedBytes.bytesAvailable > 0; i++) {
var sample:Number = recordedBytes.readFloat();
e.data.writeFloat(sample);
e.data.writeFloat(sample);
}
}
}
}