title: Android: MediaPlayer finalized without being released
body: <p>I'm using the MediaPlayer class in an app that I'm currently working on.  I want to hold on to an instance of the MediaPlayer class for the lifetime of my Activity.  I'm releasing the resources from the MediaPlayer class in the onPause() { } method of the activity, however when the activity starts I see the following warning pop up in the LogCat window:</p>
  
  <pre><code>W/MediaPlayer-JNI(16795): MediaPlayer finalized without being released
  </code></pre>
  
  <p>Any idea what I'm doing wrong here or how to remove this warning? It doesn't appear to cause any issues and the sound works just fine.</p>
  
  <p>I have a bit too much code to post because I wrapped a few objects to allow state to be managed (the MediaPlayer class doesn't currently provide state information), and various other reasons, but the code is pretty much:</p>
  
  <pre><code>@Override
  public void onCreate(Bundle savedInstanceState)
  {
      super.onCreate(savedInstanceState);
      initialiseSounds(this);
  }
  
  @Override
  protected void onPause()
  {
      soundManager.releaseResources();
  }
  
  @Override
  protected void onResume()
  {
      initialiseSounds(this);
  }
  </code></pre>
  
  <p>With this method in my SoundManager class:</p>
  
  <pre><code>public void releaseResources()
  {
      player.release();
  }
  </code></pre>
  
  <p>And in initialiseSounds I'm doing:</p>
  
  <pre><code>MediaPlayer player = new MediaPlayer();
  player.reset();
  player.setAudioStreamType(AudioManager.STREAM_MUSIC);
  AssetFileDescriptor assetFileDescriptor = context.getResources().openRawResourceFd(resourceId);
  setDataSource(player, assetFileDescriptor);
  </code></pre>
  
  <p>When I want to play the track I do:</p>
  
  <pre><code>player.prepare();
  player.start();
  </code></pre>
  
  <p>Appreciate any advice,</p>
  
  <p>Thanks,</p>