2012-05-25 3 views
0

Eclipse에서 일부 오디오 파일을 가져 오는 데 문제가 없습니다. Java가 Android 화면의 버튼을 누르고 모든 오디오 음질이 좋으면 제대로 재생됩니다. 그러나, 내가하려고하는 프로그램은 비트 메이커 스튜디오이며 버튼을 너무 빨리 누르기 만 할 수 있습니다. 바로 이전에 동일한 버튼을 누른 후 (약 0.5 초) 버튼을 눌러 오디오 샘플을 실행할 수있는 경우 약간의 지연이 있습니다. 분명히 이것은 원하는 시간에 버튼을 누를 수있을 때 뮤직 앱의 문제점을 나타냅니다. 더 빠른 버튼 누르기를 허용하려면 어떻게해야합니까?느린 버튼 Eclipse 용 Android SDK에서 실행

package studio.music; 

import android.app.Activity; 
import android.graphics.Color; 
import android.media.MediaPlayer; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 

public class StudioActivity extends Activity implements OnClickListener{ 

MediaPlayer mp1,mp2; 
Button button_one,button_two; 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { //The activity is being Created Create any threads/streams here 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    mp1 = MediaPlayer.create(this, R.raw.bassfifteen); 
    mp2 = MediaPlayer.create(this, R.raw.snarenine); 
     button_one = (Button) findViewById(R.id.buttonOne); 
      button_one.setOnClickListener(this);    
     button_two = (Button) findViewById(R.id.buttonTwo); 
      button_two.setOnClickListener(this);   
} 

@Override 
protected void onStart(){ //The activity is about to become visible 
    super.onStart();  
    //TODO set state for program start 
} 

@Override 
protected void onResume(){ //The activity has become visible(it is now "resumed") 
    super.onResume(); 
    //TODO set state for program resume 
} 

@Override 
protected void onPause(){ // Another activity is taking focus (this activity will be "paused") 
    super.onPause(); 
    //TODO set state for program hang 
} 

@Override 
protected void onStop(){ // This activity is no longer visibled (it is "stopped") 
    super.onStop(); 
    //TODO set state for program drop back 
} 

@Override 
protected void onDestroy(){ // The Activity is about too be destoryed (exiting) Destroy all threads and streams here 
    super.onDestroy(); 
    //TODO set state for program exit 
} 

@Override 
public void onClick(View v) { 

//Where the audio is fired 
if(v == button_one){ mp1.start();} 
if(v == button_two){ mp2.start();} 
} 

} 낮은 대기 시간 재생을 제공

답변

0

아마도 SoundPool으로 가야합니다. MediaPlayer에 컴파 일할 때 사운드 풀은 상당히 가벼운 객체이기 때문에. 여기에 두 가지 비교가 있습니다.

http://www.stealthcopter.com/blog/2010/08/android-soundpool-vs-mediaplayer-focus-on-soundboards-and-memory-problems/

그리고 당신은 SoundPool을 볼 수

작은 파일을 desgined된다. 여기

https://stackoverflow.com/a/5339437/603744

+0

고마워 soundpool workepd PERFECTLY .. SoundPool이 작업 간단하고 좋은 않는 내용의 다른 링크입니다. 프레스와 유지 품질 간의 미묘한 차이. 도움 감사 – KendalH