Android url mp3 out of bounds
<p>Hi guys i built an mp3 player which plays mp3s which are hosted on urls. My next button adds to a counter each time it is pressed in order to play the next mp3(interestingly enough). The problem is when there are no url paths left in my array. So when this happens and i click next, the counter exceeds the array size and my app crashes out with: Unfortunately Application has stopped working. I tried to reset the counter back to 0 in my onClick listener in the else statement, but that does nothing. How can i get it to reset back to 0 so it can play the first url once it reaches the end of the songs_urls array?</p>

<p>Here is my code:</p>

<pre><code>final String songs_urls[]={
        "https://ia601605.us.archive.org/26/items/Service_201303/service.mp3"
        ,"https://ia601607.us.archive.org/0/items/123012_20130/12%2030%2012.mp3"
        ,"https://ia601607.us.archive.org/22/items/AwakeThePlanetPorSiempre/Awake%20The%20Planet%20%20Por%20Siempre.mp3"
                         };
private MediaPlayer mediaPlayer;
private int counter;
AudioManager audioManager;

protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.services);



     ImageButton prev = (ImageButton) findViewById(R.id.previous);
     ImageButton next = (ImageButton) findViewById(R.id.next);
     ImageButton playB = (ImageButton) findViewById(R.id.play);
     ImageButton pause = (ImageButton) findViewById(R.id.pause);
     SeekBar volume = (SeekBar) findViewById(R.id.volume);
     final TextView title = (TextView)findViewById(R.id.title);
     Typeface font = Typeface.createFromAsset(getAssets(), "coneria.ttf");  
     title.setTypeface(font);
     TextView txt = (TextView)findViewById(R.id.warning);
     txt.setTypeface(font);

     counter = 0;
     audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
     int maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
     int curVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
     volume.setMax(maxVolume);
     volume.setProgress(curVolume);

     volume.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress,
                boolean fromUser) {
            // TODO Auto-generated method stub
            audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, progress, 0);

        }
    });

     mediaPlayer = new MediaPlayer();
     mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);

     next.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if(counter &lt; songs_urls.length)
                {
                counter= counter + 1;
                title.setText(songs_urls[counter]);



                try{
                    mediaPlayer.reset();
                }catch(Exception ex){

                }

                try {
                    mediaPlayer.setDataSource(songs_urls[counter]);
                } 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();
                }
                try {
                    mediaPlayer.prepare();
                } catch (IllegalStateException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                mediaPlayer.start();


                }
                else
                {
                    counter= 0;
                Toast.makeText(Services.this, "Last Song", 1500).show();
                }



            }
        });
</code></pre>
