2017-11-17 8 views
1

1 분마다 "Searching"이라고 말한 오디오 파일을 재생하려면 반복하고 싶습니다. CASE_STATUS_SEARCHING이 다른 것으로 변경 될 때 어떻게 구현하여이 파일을 중지 할 수 있습니까? 나는 TIMERSOUNDPOOL 사용 :오디오 파일을 반복하고 작업이 변경되면 중지하십시오

public class Player { 
private static SoundPool soundPool; 
private static int searching; 
final Timer timer = new Timer(); 


public void searching() { 
    timer.schedule(new TimerTask() { 
         @Override 
         public void run() { 
          soundPool.play(searching, 1.0f, 1.0f, 1, 0, 1.0f); 
         } 
        }, 60000); 
} 

//를하고 여기 스레드를 시작합니다

public class Locator BroadcastReceiver extends BroadcastReceiver { 
@Override 
public void onReceive (Context context, Intent intent) { 
final String action = intent.getAction(); 

switch (newStatus) { 
    case STATUS_SEARCHING: 
         stateStr = getString(R.string.Scanning); 
         tvStatus.setText(R.string.Scanning); 
         Player.searching(); 
         break; 
} 

답변

0

내가 유래에서 약간의 도움으로 내 자신에 그것을 해결했다.

public void playStillSearching() { 

    if (handler == null) { 
      handler = new Handler(); 
      handler.postDelayed(runnable = new Runnable() { 
       @Override 
       public void run() { 
        soundPool.play(stillSearching, 1.0f, 1.0f, 1, 0, 1.0f); 
        handler.postDelayed(this, 3000); 
       } 
      }, 3000); 
    } 
} 

public void stopSpeak() { 

    if (handler != null) { 
     handler.removeCallbacks(runnable); 
    } 
} 

나는 내 이벤트에 구현했습니다.

관련 문제