title: How to add loading dialog while media player is in preparing in service (Android)
body: <p>I built app to play audio from internet, I use service to play audio in background, the question is how to show loding dialog while media player is in preparing posision in service(background) hire my Code.</p>
  
  <h1>Activity</h1>
  
  <pre><code>package com.uqifm.onlineradio;
  .......
  public class MainActivity extends AppCompatActivity {
  
      Button b_play;
      Boolean started = false;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          requestWindowFeature(Window.FEATURE_NO_TITLE);
  
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          b_play = (Button) findViewById(R.id.b_play);
  
          b_play.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  if(started){
                      started = false;
                      stopService(new Intent(MainActivity.this,MyService.class));
                      b_play.setText("PLAY");
                  }else{
                      started = true;
                      startService(new Intent(MainActivity.this,MyService.class));
                      b_play.setText("STOP");
                  }
              }
          });
      }
  
      @Override
      protected void onDestroy() {
          super.onDestroy();
          stopService(new Intent(MainActivity.this,MyService.class));
      }
  }
  </code></pre>
  
  <h1>Service</h1>
  
  <pre><code>package com.uqifm.onlineradio;
  ....................
  public class MyService extends Service {
  
      MediaPlayer mediaPlayer;
      String stream = "http://xxxxx:36365";
  
      @Override
      public IBinder onBind(Intent intent) {
          return null;
      }
  
      @Override
      public void onCreate() {
          mediaPlayer = new MediaPlayer();
          mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
          try {
              mediaPlayer.setDataSource(stream);
              mediaPlayer.prepare();
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
  
      @Override
      public int onStartCommand(Intent intent, int flags, int startId) {
          mediaPlayer.start();
          return super.onStartCommand(intent, flags, startId);
      }
  
      @Override
      public void onDestroy() {
          mediaPlayer.release();
      }
  }
  </code></pre>