Hi,
I am developing a media player which uses a local service. I am
getting JDI thread evaluation error, exception in async thread.
My code is as below:
This is in the Activity class :
I create a thread which starts my local service, binds the activity to
the service and then gets the media player current position and the
duration from the service till the end of the song.
mConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName
className, IBinder service) {
mBoundService =
((IMusicService.LocalBinder)service).getService();
Log.i("LocalService","OnserviceConnected");
}
public void onServiceDisconnected(ComponentName
className) {
mBoundService = null;
Log.i("onservicedisconnected", "service getting
disconnected");
}
};
new Thread(new Runnable() {
public void run() { //this will be execute by the new thread
boolean bind = bindService(i, mConnection,
Context.BIND_AUTO_CREATE);
startService(i);
while (! reached || isPlaying ) {
// mProgressStatus = setProgress();
if(bind){
if(mBoundService!=null){
pBarPosition=
mBoundService.getCurrentPosition();
duration = mBoundService.getDuration();
if((pBarPosition == duration)){
reached = true;
stopService(i);
Log.i("stopped
service","stopped service");
}
if (mProgress != null) {
if (duration > 0) {
mProgressStatus = (int)(100L *
pBarPosition /
duration);
//Log.i("mProgressStatus","strings");
}
}
}
}
else
Log.i("service is null","service is null in this
thread");
pCurrentTime = stringForTime(pBarPosition);
pEndTime = stringForTime(duration);
newHandler.post(new Runnable() {
public void run() {
mProgress.setProgress(mProgressStatus);
mEndTime.setText(pEndTime);
mCurrentTime.setText(pCurrentTime);
}
});
}
}
}).start();
In my service I do the following:
public void onStart(Intent intent, int startId) {
//super.onStart(intent, startId);
android.os.Debug.waitForDebugger(); // this was for debugging
Bundle b = intent.getExtras();
path = b.getString("path"); // getting the url
path
for the song to be played which I pass from my activity
Log.i("path",path);
new Thread(new Runnable() {
public void run() { //this will be execute by the new
thread - i create the mediaplayer and start it in this thread
try
{
mMediaPlayer.setDataSource(path);
mMediaPlayer.prepare();
}
catch (Exception e)
{
e.printStackTrace();
}
mMediaPlayer.start();
currentPosition = mMediaPlayer.getCurrentPosition();
duration = mMediaPlayer.getDuration();
isPlaying = mMediaPlayer.isPlaying();
playing = pausePressed();
mHandler.post(new Runnable() {
public void run() { //
here i return all the values calculated to the main service thread..
setCP();
setDuration();
setP();
}
});
}
}).start();
Please can anyone let me know if they encountered any such problems
while creating a local service where you need to pass values from the
activity to the service and vice versa.
Thanks,
Prajakta
--
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