Make Online Radio app faster in streaming
<p>Hello i have make one radio app in that streaming is done from web</p>

<p>my source code is</p>

<p>when user click on button following code will be executed </p>

<pre><code>      if (!NotifyService.iSserviceRunning) {
            new PlayRadio().execute("");
        } 
</code></pre>

<p>// AYSNC class for start Service and create progressbar</p>

<pre><code>  class PlayRadio extends AsyncTask&lt;String, Void, String&gt; {
    @Override
    protected String doInBackground(String... urls) {
        return "";
    }

    @Override
    protected void onPostExecute(String result) {
        try {
            startService(new Intent(RadioActivity.this, NotifyService.class));
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        try {
            PD = ProgressDialog.show(RadioActivity.this, "Tuning...", "Please Wait...");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
</code></pre>

<p>//Now service class will be </p>

<pre><code>   public class NotifyService extends Service {

private static String RADIO_STATION_URL;
public static  MediaPlayer player;
public static boolean iSserviceRunning = false;
@Override
public IBinder onBind(Intent intent) {
    return null;
}

@Override
public void onCreate() {
    super.onCreate();
    RADIO_STATION_URL = getResources().getString(R.string.streamurl);
    nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    initializeMediaPlayer();
    startPlaying();
    iSserviceRunning = true;
}

@Override
public void onDestroy() {
    super.onDestroy();
    nm.cancel(R.string.service_started);
    stopPlaying();
    initializeMediaPlayer();
    iSserviceRunning = false;
}


private void startPlaying() {
    player.setOnPreparedListener(new OnPreparedListener() {
        public void onPrepared(MediaPlayer mp) {
            player.start();

        }
    });
    new PrepareTask().execute();
}

private void stopPlaying() {
    if (player.isPlaying()) {
        player.pause();
        player.release();
    }
}

private void initializeMediaPlayer() {
    player = new MediaPlayer();

    try {
        player.setDataSource(RADIO_STATION_URL);
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

}

private class PrepareTask extends AsyncTask&lt;Integer, Integer, Integer&gt; {

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
    }

    protected void onPostExecute(Integer result) {
        if(RadioActivity.PD!=null){
            if(RadioActivity.PD.isShowing()){
                RadioActivity.PD.dismiss();             
            }
        }
    }

    @Override
    protected Integer doInBackground(Integer... arg0) {
        try {
            player.prepare();
        } catch (IllegalStateException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}
</code></pre>

<p>}</p>

<p>is there any wrong i am doing becuase my client said that application is taking tooo much time for loading.. he told me that he has many such application which is loading fastly then my app</p>

<p>can any body suggest me is any wrong i have done in my code so it's taking much time?</p>
