0

我想在我的钢琴应用程序中实现录音。为此,我节省了播放每个声音的时间以及在 LinkedList 中播放的声音。要用这个时间和声音播放录制的音乐(声音序列),我们应该在指定的时间播放每个声音。这是怎么做的?这是我的一个声音代码的一部分(注):

public class MainActivity extends Activity {

double StartTime;
double millis;
sound_pool snd;
LinkedList<list> rec_list = new LinkedList<list>();

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // Create an instance of our sound manger
    snd = new sound_pool(getApplicationContext());
    // Set volume rocker mode to media volume
    this.setVolumeControlStream(AudioManager.STREAM_MUSIC);

    Button btn = (Button) findViewById(R.id.button1);       
    Date dt=new Date();
    long mil=dt.getTime();

    btn.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {

            if (event.getAction() == MotionEvent.ACTION_DOWN ) 

               {
                snd.play_s_r_1();                   
                Date dt=new Date();
                long mil=dt.getTime();                  
                rec_list.add(new list(mil,"s_r_1"));        
               }
             return true;                   
        }
    });  // end of ontouch listener 

} //end of oncreate
} //end of activity    
4

1 回答 1

0

只需尝试以下代码 public CountDownTimer (long millisInFuture, long countDownInterval) millisInFuture - 从调用 start() 到倒计时完成并调用 onFinish() 的未来毫秒数。因此 onFinish() 将在 1 秒(1000 毫秒 = 1 秒)后被调用。

   player = MediaPlayer.create(getApplicationContext(), R.raw.beepsound);
 player.start();

CountDownTimer timer = new CountDownTimer(1000, 1000) {

@Override
public void onTick(long millisUntilFinished) {
   // Nothing to do
}

@Override
public void onFinish() {
    if (player.isPlaying()) {
         player.stop();
         player.release();
    }
}
};
timer.start(); 

参考: http: //developer.android.com/reference/android/os/CountDownTimer.html#CountDownTimer (long , long)

于 2013-04-19T14:38:52.980 回答