Hi Guys,
m using service to play a audio file in background.
This is my PreviewServices class .
package com.hungama.myplay.activity;
import java.io.IOException;
import com.hungama.myplay.db.DBManager;
import com.hungama.myplay.model.DataManager;
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");
}
});
I dont know Y its throws Null Pointer Exception in this line
*MusicScreen.this.preview.player.setOnCompletionListener(newOnCompletionListener()
*
**
*please suggest me where is problem.*
*thanks in advance.*
*Gaurav Gupta*
**
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en