title: Determine what Context variable to use in MediaPlayer.create in Android
body: <p>Knotty problem with MP3 stream <code>MediaPlayer</code> in Android. I've done yet some app with it, but now I refactor the code cause of some reasons.</p>
  
  <p>There is a call of a Service in the activity of Player:</p>
  
  <pre><code>mp3Service.playSong(getBaseContext(),url);
  </code></pre>
  
  <p>The playSong method consists of this:</p>
  
  <pre><code>public void playSong(Context c, String url) {
       if (this.currenturl.equals(""))
       {
  
           this.mplayer = MediaPlayer.create(c, Uri.parse(url));
           this.currenturl=url;
           this.mplayer.start();
       }
       else
          {
          if (!this.currenturl.equals(url))
          {
                  this.mplayer.stop();
                 //this.mplayer=null; 
                   this.mplayer = MediaPlayer.create(c, Uri.parse(url));
                   this.mplayer.start();
                   this.currenturl=url;
  
          } else
          {
              if (this.on==false)
              this.mplayer.start();
  
          };
  
          };
       this.on=true;
  }
  </code></pre>
  
  <p>The call to <code>playSong</code> method worked normally when it was on the <code>ImageView</code> click listener! The music started to play.</p>
  
  <p>But, when calling simply from player activity <code>onCreate</code> - it stops the app.
  Not sure why, but it's totally hard to understand what context parameter to use here.
  I've read some similar articles and documentation, but there is much fog.</p>
  
  <p>How to determine what should I use for the first Context parameter here?
  Does it depend on from where I call the <code>.playSong(Context, Uri)</code>? If yes, how?
  Context is very abstract for new in Android, the class documentation by itself don't shed light to it.</p>
  
  <p>There are many choices which I tried but I need logical reason why to use this and how to determine why app stops.</p>
  
  <ol>
  <li><code>getApplicationContext()</code></li>
  <li><code>getBaseContext()</code></li>
  <li><code>this</code></li>
  <li><code>PlayerActivity.this</code></li>
  </ol>
  
  <p>and others. But without understanding it's not right. Maybe the error is in the other place.
  But without the service call all was working.</p>