Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Nov 25th, 2013  |  syntax: None  |  size: 1.13 KB  |  views: 31  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. public class PlayerService extends Service implements OnErrorListener {
  2. ....
  3. ////////////////////
  4.  
  5. this.mplayer = MediaPlayer.create(c, Uri.parse(url));
  6. mplayer.setOnErrorListener(onErrorListener);
  7. ////////////////////
  8.  
  9. MediaPlayer.OnErrorListener onErrorListener = new MediaPlayer.OnErrorListener()  
  10.     {  
  11.          @Override  
  12.          public boolean onError(MediaPlayer mp, int what, int extra)  
  13.          {  
  14.               Log.e(getPackageName(), String.format("Error(%s%s)", what, extra));
  15.               playlist="ERROR";
  16.  
  17.               restart();
  18.               return true;  
  19.          }  
  20.     };
  21.  
  22. @Override
  23.     public boolean onError(MediaPlayer player, int what, int extra) {
  24.         restart();
  25.         return true;
  26.     };
  27.  
  28. public void restart()
  29.     {
  30.         try
  31.         {
  32.         playlist="RELOADING";
  33.         for (int u=1; u<=5; u++)
  34.         {
  35.         Thread.sleep(5000);
  36.         mplayer.stop();
  37.         mplayer.release();
  38.         mplayer=null;
  39.     playSong(getApplicationContext(),currenturl);
  40.         };
  41.  
  42.         }
  43.         catch (Exception e)
  44.         {
  45.         playlist="RELOADING ERROR";
  46.  
  47.         }
  48.  
  49.  
  50.  
  51.     }
  52. //////////////
  53. ....
  54.  
  55. }
clone this paste RAW Paste Data