MediaPlayer's SetOnCompletionListener is not working
<p>m using service to play a audio file in background.</p>

<p>This is my PreviewServices class .</p>

<pre><code>package com.hungama.myplay.activity;
import java.io.IOException;
import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnBufferingUpdateListener;
import android.media.MediaPlayer.OnCompletionListener;
import android.net.Uri;
import android.os.Binder;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
import android.widget.MediaController;
import android.widget.Toast;

public class PreviewServices extends Service {
 private static final String TAG = "PreviewServices";
 public static MediaPlayer player;
 protected DataManager dataManager = DataManager.getInstance();
 String song_uri, url;
 private IBinder myBinder;
 private boolean isplaying;

 @Override
 public IBinder onBind(Intent intent) {
  return null;
 }

 public class MyBinder extends Binder {
  PreviewServices getService() {
   return PreviewServices.this;
  }
 }

 @Override
 public void onCreate() {
  Log.d(TAG, "onCreate " + song_uri);

 }

 @Override
 public void onDestroy() {
 player.stop();

 }

 public void onPause() {

  player.pause();
 }

 public double duration() {
  return player.getDuration();
 }

 public void onStart(Intent intent, int startid) {
   Bundle b = intent.getExtras();
  song_uri = b.getString("song_uri");
   Uri path = Uri.parse(song_uri);

  player = MediaPlayer.create(this, path);

  player.setLooping(false); // Set looping
   player.start();
/ *player.setOnCompletionListener(new OnCompletionListener() {

 public void onCompletion(MediaPlayer mp) {
  // TODO Auto-generated method stub
 Log.d("song is completed","song is not playing now");
 dataManager.setPreview_play(true);

 }
});
*/ 

 }
}

My PreviewServices is working fine, 

in My Activity i want to show a message when my song will complete.

m using this code for this purpose.

    PreviewServices preview=new PreviewServices();




MusicScreen.this.preview.player.setOnCompletionListener(new OnCompletionListener() {



public void onCompletion(MediaPlayer mp) {

// TODO Auto-generated method stub

        Log.d("song is complete","song complete");

                    }

                });
</code></pre>

<p>I dont know Y its throws Null Pointer Exception in this line</p>

<p>MusicScreen.this.preview.player.setOnCompletionListener(new OnCompletionListener()</p>

<p>please suggest  me where is problem.</p>

<p>thanks in advance.</p>

<p>Gaurav Gupta</p>
