Exemplo n.º 1
0
  private void playFile() {
    if (playingFile == null || !playingFile.isFile()) resetPlayingFile();
    if (playingFile == null) {
      Toast.makeText(AndroidWave.this, "Cannot play file", Toast.LENGTH_SHORT).show();
      return;
    }
    if (mp != null) mp.stop();
    Log.d("file to play", playingFile.getAbsolutePath());
    mp = MediaPlayer.create(AndroidWave.this, Uri.fromFile(playingFile));
    if (mp == null) {
      Toast.makeText(AndroidWave.this, "Cannot play file", Toast.LENGTH_SHORT).show();
      return;
    }
    mp.setOnCompletionListener(
        new OnCompletionListener() {

          @Override
          public void onCompletion(MediaPlayer arg0) {
            stopPlayFile();
          }
        });
    sm.stop();
    mp.start();
    playButton.setText(R.string.stop);
    playButton.setBackgroundColor(0xFF009900);
  }
Exemplo n.º 2
0
  protected void stopPlayFile() {
    mp.stop();
    mp.release();
    mp = null;

    playButton.setText(R.string.play);
    playButton.setBackgroundColor(0xFF00CC00);
    sm.start();

    return;
  }
Exemplo n.º 3
0
 @Override
 public void onResume() {
   super.onResume();
   dir =
       new File(
           prefs.getString(
               "data_dir",
               Environment.getExternalStorageDirectory().getPath() + "/Sound Recordings/"));
   if (mp == null && (mService == null || !mService.isRecording())) {
     sm.start();
   }
 }
Exemplo n.º 4
0
 public void onClick(View v) {
   //			Log.d("RecorderController", "mRecordListener");
   if (mService != null) {
     if (mService.isRecording()) {
       mService.stopRecording();
       recButton.setText(R.string.record);
       recButton.setBackgroundColor(0xFFCC0000);
     } else {
       sm.stop();
       //				Log.d("RecorderController", "mRecordListener:startRecording()");
       mService.startRecording(dir);
       recButton.setText(R.string.stop);
       recButton.setBackgroundColor(0xFF990000);
     }
   }
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    tx = (TextView) findViewById(R.id.sound);

    smt.start();

    new Thread(
            new Runnable() {
              double amp;

              @Override
              public void run() {
                while (true) {
                  amp = smt.getAmplitude();
                  System.out.print("Amplitude: ");
                  System.out.println(amp);
                }
              }
            })
        .start();
  }
Exemplo n.º 6
0
 @Override
 public void handleMessage(Message msg) {
   Log.i("message", msg.what + "");
   sm.start();
   setPlayingFile(new File((String) msg.obj));
 }
Exemplo n.º 7
0
 @Override
 public void onPause() {
   super.onPause();
   sm.stop();
 }