2014-01-17 3 views
0

매분마다 mPlayer를 반복 해 봅니다. 내가하는 일이 있습니다. 도와주세요.Android : 매분 음악을 반복하십시오.

int delay = 0; 
int period = 60000; 

    Timer timer = new Timer(); 
    timer.scheduleAtFixedRate(new TimerTask() { 
    public void run() { 
     mPlayer.start(); 
    } 
    }, delay, period); 
+0

alaram 관리자를 사용하십시오. – Raghunandan

+0

그 코드는 괜찮아요. 그래서 뭐가 문제 야? – Autocrab

+0

작동하지 않습니다. – Merv

답변

1

호출 시작()을보십시오. MediaPlayer의 state Diagram을 확인하십시오. seekTo()를 호출해야합니다. 그래서 아마 당신은이 같은 코드를 작성할 수 있습니다 ...

int delay = 0; 
boolean isFirstTime = true; 
int period = 60000; 

    Timer timer = new Timer(); 
    timer.scheduleAtFixedRate(new TimerTask() { 
    public void run() { 
     if (isFirstTime) { 
      isFirstTime = false; 
      mPlayer.start(); 
     } 
     else 
      mPlayer.seekTo(0); 

    } 
    }, delay, period); 
+0

아무 것도하지 않았으므로 seekTo() 대신에 – Merv

+0

을 시도하고 stop() -> prepare() -> start()를 시도하십시오 – yushulx

+0

오류 정보가 있습니다. Logcat Mediaplayer 오류 (-38, 0) – Merv

0

핸들러로 음악을 재생할 수 없습니다

new Handler().postDelayed(new Runnable() {   
    @Override   
    public void run() {    
    mPlayer.start();    
    }  
}, 60000); 
+0

을 사용합니다. 음악을 시작하기 전 1 분간 기다렸다가 1 분 후에 다시 반복하지 않습니다. – Merv

0

를 사용하여 방송 수신기를 등록하고 한 번마다 자동으로 분 미디어 플레이어 호출이 방송 수신기를 사용하는 알람 관리자를

Calendar calendarAutomticSync = Calendar.getInstance(); 
     Intent intentAutomaticSync = new Intent(Dropbox.this, 
       BroadcastReceiverDropboxAutoSync.class); 
     intentAutomaticSync.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
     String currenttimeDaily = String.valueOf((int) System 
       .currentTimeMillis()); 
     int systemCurrentTimeDaily = Integer.parseInt(currenttimeDaily); 
     pendingIntent = PendingIntent.getBroadcast(Dropbox.this, 
       systemCurrentTimeDaily, intentAutomaticSync, 0); 
     alarm_manager.setRepeating(AlarmManager.RTC_WAKEUP, 
       calendarAutomticSync.getTimeInMillis(), 1000 * 60 * 1, 
       pendingIntent); 
+0

괜찮습니다. 나는 그것을 시도 할 것이다. – Merv

+0

의심 할 여지없이 공개적으로 나에게 메시지를 보내려면 – Satheesh

+0

관심을 가져 주셔서 고맙습니다. – Merv

관련 문제