Hi Try recThread.start(); not recThread.run(); otherwise you are not executing a new thread...
Regards On Thursday, August 23, 2012 2:04:39 PM UTC+10, Argon wrote: > > Its the handler in the recording thread. It should change the button text > before thread starts audio recording but it doesnt run till long after BOTH > threads are done. can someone please tell me whats going on? > > package com.EJH.Industries.microkr; > > import android.media.AudioFormat; > import android.media.AudioManager; > import android.media.AudioRecord; > import android.media.AudioTrack; > import android.media.MediaRecorder; > import android.media.MediaSyncEvent; > import android.os.Bundle; > import android.os.Handler; > import android.app.Activity; > import android.view.Menu; > import android.view.MenuItem; > import android.view.View; > import android.view.View.OnClickListener; > import android.widget.Button; > import android.widget.Toast; > import android.support.v4.app.NavUtils; > > public class MainActivity extends Activity { > //CLASS VARIABLES > //CHAR SEQUENCE > CharSequence easyChar = "PLAYING"; > public Handler textViewHandler = new Handler(); > > //CREATE THE RECORDING OBJECT > int audioSrc = MediaRecorder.AudioSource.MIC; > int sampleRate = 44100; > int chanConfig = AudioFormat.CHANNEL_IN_MONO; > int audioFormat = AudioFormat.ENCODING_PCM_16BIT; > int getMinBuffSize = 200*AudioRecord.getMinBufferSize(sampleRate, > chanConfig, audioFormat); > int minBuffSize = (int) getMinBuffSize; > short audioBuff[] = new short[minBuffSize]; > public AudioRecord micRecorder = new AudioRecord(audioSrc, 22050, > chanConfig, audioFormat, minBuffSize); > > > > //CREATE THE PLAYBACK OBJECT > int streamType = AudioManager.STREAM_MUSIC; > int playMode = AudioTrack.MODE_STREAM; > int playChanConfig = AudioFormat. CHANNEL_OUT_MONO; > public AudioTrack speakerPlay = new AudioTrack(streamType, sampleRate, > playChanConfig, audioFormat, 8192, playMode); > > > > public void startRec(){ > micRecorder.startRecording(); > micRecorder.read(audioBuff, 0, minBuffSize); > micRecorder.stop(); > micRecorder.release(); > } > > public void startPlayback(){ > > speakerPlay.play(); > speakerPlay.write(audioBuff, 0, minBuffSize); > speakerPlay.stop(); > > } > > > > > > > > > > @Override > public void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > setContentView(R.layout.activity_main); > final Button startBtn = (Button) findViewById(R.id.startButton); > startBtn.setOnClickListener(new OnClickListener(){ > > public void onClick(View v) { > // TODO Auto-generated method stub > > > Thread recThread = new Thread( new Runnable(){ > > public void run() { > // TODO Auto-generated method stub > > > textViewHandler.post(new Runnable () { > public void run(){ > startBtn.setText("Recording!"); > } > > }); > > > startRec(); > } > > }); > > // RUN RECORDING FUNCTION > recThread.run(); > try { > recThread.join(); > } catch (InterruptedException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > } > > > Thread playThread = new Thread( new Runnable(){ > > public void run() { > // TODO Auto-generated method stub > > startPlayback(); > } > > }); > > > > > > playThread.run(); > try { > playThread.join(); > } catch (InterruptedException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > } > > > } > > }); > > ///////END onCreate////////// > } > > @Override > public boolean onCreateOptionsMenu(Menu menu) { > getMenuInflater().inflate(R.menu.activity_main, menu); > return true; > } > > > } > > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en