2013-05-27 240 views
1

我在Play商店中的某個應用程序中遇到了一個奇怪的問題。問題是我根本無法複製這個問題。這是我的遊戲商店日誌貓。任何幫助或想法將不勝感激。有9個報道。有超過10000個活躍用戶。Stackoverflow MediaPlayer Android Seekbar

java.lang.StackOverflowError 
at android.os.Message.obtain(Message.java:236) 
at android.os.Handler.obtainMessage(Handler.java:247) 
at android.media.MediaPlayer.postEventFromNative(MediaPlayer.java:1760) 
at android.media.MediaPlayer.getDuration(Native Method) 
at com.peshal.nepalisongsandmore.PlayerActivity$10.onProgressChanged(PlayerActivity.java:300) 
at android.widget.SeekBar.onProgressRefresh(SeekBar.java:89) 
at android.widget.ProgressBar.doRefreshProgress(ProgressBar.java:609) 
at android.widget.ProgressBar.refreshProgress(ProgressBar.java:621) 
at android.widget.ProgressBar.setMax(ProgressBar.java:775) 
at android.widget.AbsSeekBar.setMax(AbsSeekBar.java:180) 
at com.peshal.nepalisongsandmore.PlayerActivity$10.onProgressChanged(PlayerActivity.java:300) 
at android.widget.SeekBar.onProgressRefresh(SeekBar.java:89) 
at android.widget.ProgressBar.doRefreshProgress(ProgressBar.java:609) 
at android.widget.ProgressBar.refreshProgress(ProgressBar.java:621) 
at android.widget.ProgressBar.setMax(ProgressBar.java:775) 
at android.widget.AbsSeekBar.setMax(AbsSeekBar.java:180) 
at com.peshal.nepalisongsandmore.PlayerActivity$10.onProgressChanged(PlayerActivity.java:300) 
at android.widget.SeekBar.onProgressRefresh(SeekBar.java:89) 
at android.widget.ProgressBar.doRefreshProgress(ProgressBar.java:609) 
at android.widget.ProgressBar.refreshProgress(ProgressBar.java:621) 
at android.widget.ProgressBar.setMax(ProgressBar.java:775) 
at android.widget.AbsSeekBar.setMax(AbsSeekBar.java:180) 
at com.peshal.nepalisongsandmore.PlayerActivity$10.onProgressChanged(PlayerActivity.java:300) 
at android.widget.SeekBar.onProgressRefresh(SeekBar.java:89) 
at android.widget.ProgressBar.doRefreshProgress(ProgressBar.java:609) 
at android.widget.ProgressBar.refreshProgress(ProgressBar.java:621) 
at android.widget.ProgressBar.setMax(ProgressBar.java:775) 
at android.widget.AbsSeekBar.setMax(AbsSeekBar.java:180) 
at com.peshal.nepalisongsandmore.PlayerActivity$10.onProgressChanged(PlayerActivity.java:300) 
at android.widget.SeekBar.onProgressRefresh(SeekBar.java:89) 
at android.widget.ProgressBar.doRefreshProgress(ProgressBar.java:609) 
at android.widget.ProgressBar.refreshProgress(ProgressBar.java:621) 
at android.widget.ProgressBar.setMax(ProgressBar.java:775) 
at android.widget.AbsSeekBar.setMax(AbsSeekBar.java:180) 
at com.peshal.nepalisongsandmore.PlayerActivity$10.onProgressChanged(PlayerActivity.java:300) 
at android.widget.SeekBar.onProgressRefresh(SeekBar.java:89) 
at android.widget.ProgressBar.doRefreshProgress(ProgressBar.java:609) 
at android.widget.ProgressBar.refreshProgress(ProgressBar.java:621) 
at android.widget.ProgressBar.setMax(ProgressBar.java:775) 
at android.widget.AbsSeekBar.setMax(AbsSeekBar.java:180) 
at com.peshal.nepalisongsandmore.PlayerActivity$10.onProgressChanged(PlayerActivity.java:300) 
at android.widget.SeekBar.onProgressRefresh(SeekBar.java:89) 
at android.widget.ProgressBar.doRefreshProgress(ProgressBar.java:609) 
at android.widget.ProgressBar.refreshProgress(ProgressBar.java:621) 
at android.widget.ProgressBar.setMax(ProgressBar.java:775) 
at android.widget.AbsSeekBar.setMax(AbsSeekBar.java:180) 
at com.peshal.nepalisongsandmore.PlayerActivity$10.onProgressChanged(PlayerActivity.java:300) 
at android.widget.SeekBar.onProgressRefresh(SeekBar.java:89) 
at android.widget.ProgressBar.doRefreshProgress(ProgressBar.java:609) 
at android.widget.ProgressBar.refreshProgress(ProgressBar.java:621) 
at android.widget.ProgressBar.setMax(ProgressBar.java:775) 
at android.widget.AbsSeekBar.setMax(AbsSeekBar.java:180) 
at com.peshal.nepalisongsandmore.PlayerActivity$10.onProgressChanged(PlayerActivity.java:300) 
at android.widget.SeekBar.onProgressRefresh(SeekBar.java:89) 
at android.widget.ProgressBar.doRefreshProgress(ProgressBar.java:609) 
at android.widget.ProgressBar.refreshProgress(ProgressBar.java:621) 
at android.widget.ProgressBar.setMax(ProgressBar.java:775) 
at android.widget.AbsSeekBar.setMax(AbsSeekBar.java:180) 
at com.peshal.nepalisongsandmore.PlayerActivity$10.onProgressChanged(PlayerActivity.java:300) 
at android.widget.SeekBar.onProgressRefresh(SeekBar.java:89) 
at android.widget.ProgressBar.doRefreshProgress(ProgressBar.java:609) 
at android.widget.ProgressBar.refreshProgress(ProgressBar.java:621) 
at android.widget.ProgressBar.setMax(ProgressBar.java:775) 
at android.widget.AbsSeekBar.setMax(AbsSeekBar.java:180) 
at com.peshal.nepalisongsandmore.PlayerActivity$10.onProgressChanged(PlayerActivity.java:300) 
at android.widget.SeekBar.onProgressRefresh(SeekBar.java:89) 
at android.widget.ProgressBar.doRefreshProgress(ProgressBar.java:609) 
at android.widget.ProgressBar.refreshProgress(ProgressBar.java:621) 
at android.widget.ProgressBar.setMax(ProgressBar.java:775) 
at android.widget.AbsSeekBar.setMax(AbsSeekBar.java:180) 
at com.peshal.nepalisongsandmore.PlayerActivity$10.onProgressChanged(PlayerActivity.java:300) 
at android.widget.SeekBar.onProgressRefresh(SeekBar.java:89) 
at android.widget.ProgressBar.doRefreshProgress(ProgressBar.java:609) 
at android.widget.ProgressBar.refreshProgress(ProgressBar.java:621) 
at android.widget.ProgressBar.setMax(ProgressBar.java:775) 
at android.widget.AbsSeekBar.setMax(AbsSeekBar.java:180) 
at com.peshal.nepalisongsandmore.PlayerActivity$10.onProgressChanged(PlayerActivity.java:300) 
at android.widget.SeekBar.onProgressRefresh(SeekBar.java:89) 
at android.widget.ProgressBar.doRefreshProgress(ProgressBar.java:609) 
at android.widget.ProgressBar.refreshProgress(ProgressBar.java:621) 
at android.widget.ProgressBar.setMax(ProgressBar.java:775) 
at android.widget.AbsSeekBar.setMax(AbsSeekBar.java:180) 
at com.peshal.nepalisongsandmore.PlayerActivity$10.onProgressChanged(PlayerActivity.java:300) 
at android.widget.SeekBar.onProgressRefresh(SeekBar.java:89) 
at android.widget.ProgressBar.doRefreshProgress(ProgressBar.java:609) 
at android.widget.ProgressBar.refreshProgress(ProgressBar.java:621) 
at android.widget.ProgressBar.setMax(ProgressBar.java:775) 
at android.widget.AbsSeekBar.setMax(AbsSeekBar.java:180) 
at com.peshal.nepalisongsandmore.PlayerActivity$10.onProgressChanged(PlayerActivity.java:300) 
at android.widget.SeekBar.onProgressRefresh(SeekBar.java:89) 
at android.widget.ProgressBar.doRefreshProgress(ProgressBar.java:609) 
at android.widget.ProgressBar.refreshProgress(ProgressBar.java:621) 
at android.widget.ProgressBar.setMax(ProgressBar.java:775) 
at android.widget.AbsSeekBar.setMax(AbsSeekBar.java:180) 
at com.peshal.nepalisongsandmore.PlayerActivity$10.onProgressChanged(PlayerActivity.java:300) 
at android.widget.SeekBar.onProgressRefresh(SeekBar.java:89) 
at android.widget.ProgressBar.doRefreshProgress(ProgressBar.java:609) 
at android.widget.ProgressBar.refreshProgress(ProgressBar.java:621) 
at android.widget.ProgressBar.setMax(ProgressBar.java:775) 
at android.widget.AbsSeekBar.setMax(AbsSeekBar.java:180) 
at com.peshal.nepalisongsandmore.PlayerActivity$10.onProgressChanged(PlayerActivity.java:300) 
at android.widget.SeekBar.onProgressRefresh(SeekBar.java:89) 
at android.widget.ProgressBar.doRefreshProgress(ProgressBar.java:609) 
at android.widget.ProgressBar.refreshProgress(ProgressBar.java:621) 
at android.widget.ProgressBar.setMax(ProgressBar.java:775) 
at android.widget.AbsSeekBar.setMax(AbsSeekBar.java:180) 
at com.peshal.nepalisongsandmore.PlayerActivity$10.onProgressChanged(PlayerActivity.java:300) 
at android.widget.SeekBar.onProgressRefresh(SeekBar.java:89) 
at android.widget.ProgressBar.doRefreshProgress(ProgressBar.java:609) 
at android.widget.ProgressBar.refreshProgress(ProgressBar.java:621) 
at android.widget.ProgressBar.setMax(ProgressBar.java:775) 
at android.widget.AbsSeekBar.setMax(AbsSeekBar.java:180) 
at com.peshal.nepalisongsandmore.PlayerActivity$10.onProgressChanged(PlayerActivity.java:300) 
at android.widget.SeekBar.onProgressRefresh(SeekBar.java:89) 
at android.widget.ProgressBar.doRefreshProgress(ProgressBar.java:609) 
at android.widget.ProgressBar.refreshProgress(ProgressBar.java:621) 
at android.widget.ProgressBar.setMax(ProgressBar.java:775) 
at android.widget.AbsSeekBar.setMax(AbsSeekBar.java:180) 
at com.peshal.nepalisongsandmore.PlayerActivity$10.onProgressChanged(PlayerActivity.java:300) 
at android.widget.SeekBar.onProgressRefresh(SeekBar.java:89) 
at android.widget.ProgressBar.doRefreshProgress(ProgressBar.java:609) 
at android.widget.ProgressBar.refreshProgress(ProgressBar.java:621) 
at android.widget.ProgressBar.setMax(ProgressBar.java:775) 
at android.widget.AbsSeekBar.setMax(AbsSeekBar.java:180) 
at com.peshal.nepalisongsandmore.PlayerActivity$10.onProgressChanged(PlayerActivity.java:300) 
at android.widget.SeekBar.onProgressRefresh(SeekBar.java:89) 
at android.widget.ProgressBar.doRefreshProgress(ProgressBar.java:609) 
at android.widget.ProgressBar.refreshProgress(ProgressBar.java:621) 
at android.widget.ProgressBar.setMax(ProgressBar.java:775) 
at android.widget.AbsSeekBar.setMax(AbsSeekBar.java:180) 
at com.peshal.nepalisongsandmore.PlayerActivity$10.onProgressChanged(PlayerActivity.java:300) 
at android.widget.SeekBar.onProgressRefresh(SeekBar.java:89) 
at android.widget.ProgressBar.doRefreshProgress(ProgressBar.java:609) 
at android.widget.ProgressBar.refreshProgress(ProgressBar.java:621) 
at android.widget.ProgressBar.setMax(ProgressBar.java:775) 
at android.widget.AbsSeekBar.setMax(AbsSeekBar.java:180) 
at com.peshal.nepalisongsandmore.PlayerActivity$10.onProgressChanged(PlayerActivity.java:300) 
at android.widget.SeekBar.onProgressRefresh(SeekBar.java:89) 
at android.widget.ProgressBar.doRefreshProgress(ProgressBar.java:609) 
at android.widget.ProgressBar.refreshProgress(ProgressBar.java:621) 
at android.widget.ProgressBar.setMax(ProgressBar.java:775) 
at android.widget.AbsSeekBar.setMax(AbsSeekBar.java:180) 
at com.peshal.nepalisongsandmore.PlayerActivity$10.onProgressChanged(PlayerActivity.java:300) 
at android.widget.SeekBar.onProgressRefresh(SeekBar.java:89) 
at android.widget.ProgressBar.doRefreshProgress(ProgressBar.java:609) 
at android.widget.ProgressBar.refreshProgress(ProgressBar.java:621) 
at android.widget.ProgressBar.setMax(ProgressBar.java:775) 
at android.widget.AbsSeekBar.setMax(AbsSeekBar.java:180) 
at com.peshal.... 

這裏是PlayerActivity.java

代碼
package com.peshal.nepalisongsandmore; 

import java.io.IOException; 
import java.util.ArrayList; 
import com.actionbarsherlock.app.SherlockActivity; 
import android.media.AudioManager; 
import android.media.MediaPlayer; 
import android.media.MediaPlayer.OnBufferingUpdateListener; 
import android.media.MediaPlayer.OnCompletionListener; 
import android.media.MediaPlayer.OnPreparedListener; 
import android.os.AsyncTask; 
import android.os.Bundle; 
import android.support.v4.app.NotificationCompat; 
import android.telephony.TelephonyManager; 
import android.util.Log; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.ImageView; 
import android.widget.SeekBar; 
import android.widget.SeekBar.OnSeekBarChangeListener; 
import android.widget.TextView; 
import android.app.Notification; 
import android.app.NotificationManager; 
import android.app.PendingIntent; 
import android.content.Context; 
import android.content.Intent; 
import android.graphics.drawable.AnimationDrawable; 


public class PlayerActivity extends SherlockActivity { 
    MediaPlayer mediaPlayer = MediaPlayerSingleton.mediaPlayer; 
    NotificationManager mNotificationManager; 
    Button play; 
    Button forward; 
    Button rewind; 
    Button pause; 
    Button previous; 
    Button next; 
    ImageView img; 
    SeekBar seekBar; 
    String mediaType; 
    AnimationDrawable frameAnimation; 
    TextView textView; 
int position; 
ArrayList<String> urls; 
String url; 


    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_player); 
     frameAnimation = new AnimationDrawable(); 
     img = (ImageView)findViewById(R.id.equalizer_anim); 
     textView = (TextView) findViewById(R.id.songinfo); 

    // new LoadEqualizer().execute(); 
     if(mediaPlayer!=null) { 
      mediaPlayer.reset(); 
     } 

     mediaType = getIntent().getExtras().getString("mediaType"); 
     if(mediaType.equals("songs")) { 
     position = getIntent().getExtras().getInt("position"); 
     urls = getIntent().getStringArrayListExtra("urls"); 
     } 
     else if(mediaType.equals("radios")) { 
      url = getIntent().getExtras().getString("radioUrl"); 
      //radioName = getIntent().getExtras().getString("radioName"); 
     } 


     play = (Button)findViewById(R.id.play); 
     seekBar = (SeekBar)findViewById(R.id.seekBar1); 
     forward = (Button)findViewById(R.id.forward); 
     rewind = (Button)findViewById(R.id.rewind); 
     pause = (Button)findViewById(R.id.pause); 
     previous =(Button) findViewById(R.id.previous); 
     next=(Button) findViewById(R.id.next); 
     play.setVisibility(View.GONE); 
     pause.setVisibility(View.GONE); 
     previous.setVisibility(View.GONE); 
     next.setVisibility(View.GONE); 
     rewind.setVisibility(View.GONE); 
     forward.setVisibility(View.GONE); 

     textView.setText("Buffering.."); 
     playMusic(); 

    } 



    public void playMusic() { 
     frameAnimation.addFrame(getResources().getDrawable(R.drawable.equalizer1), 50); 
     frameAnimation.addFrame(getResources().getDrawable(R.drawable.equalizer2), 50); 
     frameAnimation.addFrame(getResources().getDrawable(R.drawable.equalizer3), 50); 
     frameAnimation.addFrame(getResources().getDrawable(R.drawable.equalizer4), 50); 
     frameAnimation.addFrame(getResources().getDrawable(R.drawable.equalizer5), 50); 
     frameAnimation.addFrame(getResources().getDrawable(R.drawable.equalizer6), 50); 
     frameAnimation.addFrame(getResources().getDrawable(R.drawable.equalizer7), 50); 
     frameAnimation.addFrame(getResources().getDrawable(R.drawable.equalizer8), 50); 
     frameAnimation.addFrame(getResources().getDrawable(R.drawable.equalizer9), 50); 
     frameAnimation.addFrame(getResources().getDrawable(R.drawable.equalizer10), 50); 
     frameAnimation.addFrame(getResources().getDrawable(R.drawable.equalizer11), 50); 
     frameAnimation.addFrame(getResources().getDrawable(R.drawable.equalizer12), 50); 
     frameAnimation.addFrame(getResources().getDrawable(R.drawable.equalizer13), 50); 
     frameAnimation.addFrame(getResources().getDrawable(R.drawable.equalizer14), 50); 
     frameAnimation.addFrame(getResources().getDrawable(R.drawable.equalizer15), 50); 
     frameAnimation.addFrame(getResources().getDrawable(R.drawable.equalizer16), 50); 
     frameAnimation.addFrame(getResources().getDrawable(R.drawable.equalizer17), 50); 
     frameAnimation.addFrame(getResources().getDrawable(R.drawable.equalizer18), 50); 
     frameAnimation.addFrame(getResources().getDrawable(R.drawable.equalizer19), 50); 
     frameAnimation.addFrame(getResources().getDrawable(R.drawable.equalizer20), 50); 
     frameAnimation.setOneShot(false); 
     img.setBackgroundDrawable(frameAnimation); 
     frameAnimation.start(); 
     frameAnimation.stop(); 

     mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); 
     try { 
      if(mediaType.equals("songs")) { 
      mediaPlayer.setDataSource(urls.get(position)); 
      } 
      else if (mediaType.equals("radios")) { 
      mediaPlayer.setDataSource(url); 
      } 
     } catch (IllegalArgumentException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } catch (SecurityException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } catch (IllegalStateException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
     mediaPlayer.prepareAsync(); 

     mediaPlayer.setOnPreparedListener(new OnPreparedListener(){ 

      @Override 
      public void onPrepared(MediaPlayer mp) { 
       mediaPlayer.start(); 
       frameAnimation.start(); 
       if (mediaType.equals("songs")) { 

       rewind.setVisibility(View.VISIBLE); 
       forward.setVisibility(View.VISIBLE); 
       previous.setVisibility(View.VISIBLE); 
       next.setVisibility(View.VISIBLE); 
       seekBar.setMax(mediaPlayer.getDuration()); 
      } 
       pause.setVisibility(View.VISIBLE); 
       textView.setText(""); 
      } 

     }); 



     pause.setOnClickListener(new OnClickListener(){ 

      @Override 
      public void onClick(View view) { 
       mediaPlayer.pause(); 
       frameAnimation.stop(); 
       play.setVisibility(View.VISIBLE); 
       pause.setVisibility(View.GONE); 
       rewind.setVisibility(View.GONE); 
       forward.setVisibility(View.GONE); 

      } 

     }); 
     play.setOnClickListener(new OnClickListener(){ 

      @Override 
      public void onClick(View v) { 
       mediaPlayer.start();  
       frameAnimation.start(); 
       play.setVisibility(View.GONE); 
       if (mediaType.equals("songs")) { 
       pause.setVisibility(View.VISIBLE); 

       rewind.setVisibility(View.VISIBLE); 
       forward.setVisibility(View.VISIBLE); 
       } 

      } 

     }); 
     forward.setOnClickListener(new OnClickListener(){ 

      @Override 
      public void onClick(View v) { 
       mediaPlayer.seekTo(mediaPlayer.getCurrentPosition() + 1000); 

      } 

     }); 
     previous.setOnClickListener(new OnClickListener(){ 

      @Override 
      public void onClick(View v) { 
       if (position==0) { 
       position = urls.size() -2; 
       } 
       else { 
        position = position-2; 
       } 
       mediaPlayer.stop(); 
       mediaPlayer.reset(); 
       play.setVisibility(View.GONE); 
       pause.setVisibility(View.GONE); 
       previous.setVisibility(View.GONE); 
       next.setVisibility(View.GONE); 
       rewind.setVisibility(View.GONE); 
       forward.setVisibility(View.GONE); 
       getNextTrack(); 

      } 

     }); 
     next.setOnClickListener(new OnClickListener(){ 

      @Override 
      public void onClick(View v) { 
       mediaPlayer.stop(); 
       mediaPlayer.reset(); 
       play.setVisibility(View.GONE); 
       pause.setVisibility(View.GONE); 
       previous.setVisibility(View.GONE); 
       next.setVisibility(View.GONE); 
       rewind.setVisibility(View.GONE); 
       forward.setVisibility(View.GONE); 
       getNextTrack(); 

      } 

     }); 
     rewind.setOnClickListener(new OnClickListener(){ 

      @Override 
      public void onClick(View v) { 
       mediaPlayer.seekTo(mediaPlayer.getCurrentPosition() - 1000); 

      } 

     }); 


     mediaPlayer.setOnCompletionListener(new OnCompletionListener(){ 

      @Override 
      public void onCompletion(MediaPlayer mediaPlayer) { 
       mediaPlayer.reset(); 
       frameAnimation.stop(); 

       if(mediaType.equals("songs")) { 
        getNextTrack(); 

      } 
      } 

     }); 
     mediaPlayer.setOnBufferingUpdateListener(new OnBufferingUpdateListener(){ 
      int state; 

      @Override 
      public void onBufferingUpdate(MediaPlayer mediaPlayer, int percent) { 
       seekBar.setProgress(mediaPlayer.getCurrentPosition()); 
       TelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); 
       state = tm.getCallState(); 
       if(state==TelephonyManager.CALL_STATE_OFFHOOK|| state==TelephonyManager.CALL_STATE_RINGING) { 
        mediaPlayer.pause(); 
        new CallHandler().execute(); 
       } 
      } 

     }); 


     seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener(){ 

      @Override 
      public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { 
       seekBar.setMax(mediaPlayer.getDuration()); 
       if(fromUser){    
        mediaPlayer.seekTo(progress); 
        } 

      } 

      @Override 
      public void onStartTrackingTouch(SeekBar seekBar) { 


      } 

      @Override 
      public void onStopTrackingTouch(SeekBar seekBar) { 


      } 

     }); 

    } 

    Intent intent; 
    NotificationManager notificationManager; 

    @Override 
    protected void onPause() { 
     if(MediaPlayerSingleton.mediaPlayer.isPlaying()) { 

      notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); 
      intent = new Intent(getApplicationContext(), PlayerActivity.class);  
      intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP| Intent.FLAG_ACTIVITY_SINGLE_TOP); 
      PendingIntent pIntent = PendingIntent.getActivity(getBaseContext(), 0, intent,0); 
      NotificationCompat.Builder noti = 
        new NotificationCompat.Builder(this) 
        .setSmallIcon(android.R.drawable.ic_media_play) 
        .setContentTitle("Nepali Music And more") 
        .setContentText("Playing"); 
     noti.setContentIntent(pIntent); 
     noti.setAutoCancel(true); 
     noti.setOngoing(true); 
     Notification notification = noti.getNotification(); 


      notificationManager.notify(1, notification); 
     } 

     super.onPause(); 
    } 

    @Override 
    protected void onResume() { 
     if (notificationManager!=null) { 
     notificationManager.cancel(1); 
     } 
     super.onResume(); 
    } 



    public void getNextTrack() { 
     if(mediaPlayer.isLooping()||mediaPlayer.isLooping()) { 
      mediaPlayer.reset(); 
     } 
     if(position!=(urls.size()-1)) { 
      position = position + 1; 
     } 
     else{ 
      position=0; 
     } 
     playMusic(); 
    } 
public class CallHandler extends AsyncTask<Void, Void, Void> { 

    @Override 
    protected Void doInBackground(Void... params) { 
     Log.d("New asynctask started", " Call handler"); 
     TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); 
     while(tm.getCallState()==TelephonyManager.CALL_STATE_OFFHOOK|| tm.getCallState()==TelephonyManager.CALL_STATE_RINGING) { 
      try { 
       Thread.sleep(2000); 
      } catch (InterruptedException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
     } 
     mediaPlayer.start(); 
     return null; 
    } 

    @Override 
    protected void onPostExecute(Void result) { 
     Log.d("asynctask finished", " Call handler"); 
     super.onPostExecute(result); 
    } 

} 

} 
+1

代碼在哪裏? – Geros

+0

我已添加代碼。感謝您的關注 – Peshal

+0

嘗試刪除'seekBar.setMax(mediaPlayer.getDuration())'這可能是問題的根源logcat – Geros

回答

0

onProgressChanged刪除seekBar.setMax(mediaPlayer.getDuration()); - 它並不需要在那裏,你應該在onPrepared回調準確時間,無需設置它再次在其它回調

UPDATE:

至少你需要從刪除呼叫,因爲更改SeekBar最大值可以更改進度位置並再次觸發onProgressChanged。如果您確實需要撥打setMax - 在UI線程上製作onProgressChanged計劃 - 您可以使用post(Runnable)

+0

嗨msh,感謝您的建議,刪除這將實際上比解決問題更多的事情,我剛剛嘗試過,當我刪除行onProgressChanged回調無法正常工作,它需要永遠尋求到那個位置,有時,onCompletion被調用。幾乎所有代碼都是有原因的。我在想,可能會以不同的方式解決問題。我在想,我的應用程序的很多用戶來自尼泊爾,互聯網連接並不是很好。這可能是原因嗎? – Peshal

+0

我真的不知道如何移除setMax可以破壞任何東西,但至少需要將它從onProgressChanged中移除,因爲更改SeekBar max值可以更改進度位置並再次觸發onProgressChanged。如果你真的需要調用setMax - 讓onProgressChanged調度它的UI線程 - 你可以使用post(Runnable) – msh

+0

至少有一點幫助!感謝msh! – Peshal