Created
January 14, 2011 17:00
-
-
Save grapswiz/779886 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ws.graps; | |
import android.app.Activity; | |
import android.media.AudioFormat; | |
import android.media.AudioManager; | |
import android.media.AudioTrack; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.view.View.OnClickListener; | |
import android.widget.Button; | |
import android.widget.TextView; | |
import java.util.Random; | |
public class RecordActivity extends Activity | |
{ | |
Button playButton = null; | |
AudioTrack track = null; | |
int playCount = 0; | |
TextView text = null; | |
@Override | |
public void onCreate(Bundle savedInstanceState) | |
{ | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.recorder); | |
track = new AudioTrack(AudioManager.STREAM_MUSIC, 44100, AudioFormat.CHANNEL_CONFIGURATION_DEFAULT, AudioFormat.ENCODING_DEFAULT, 44100, AudioTrack.MODE_STATIC); | |
byte[] whiteNoise = new byte[44100]; | |
Random rand = new Random(); | |
rand.nextBytes(whiteNoise); | |
track.write(whiteNoise, 0, whiteNoise.length); | |
text = (TextView)findViewById(R.id.textview01); | |
playButton = (Button)findViewById(R.id.playButton); | |
playButton.setOnClickListener(new OnClickListener() { | |
public void onClick(View view) { | |
text.setText(""+playCount); | |
if(playCount > 0) { | |
track.stop(); | |
track.reloadStaticData(); | |
} | |
track.play(); | |
playCount++; | |
} | |
}); | |
} | |
@Override | |
public void onPause() | |
{ | |
super.onPause(); | |
track.stop(); | |
track.release(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment