hi,
Seems the logcat
11-26 13:32:06.727: ERROR/AndroidRuntime(10779): FATAL EXCEPTION: Timer-0
11-26 13:32:06.727: ERROR/AndroidRuntime(10779):
java.lang.IllegalStateException
11-26 13:32:06.727: ERROR/AndroidRuntime(10779): at
android.media.MediaPlayer.getCurrentPosition(Native Method)
11-26 13:32:06.727: ERROR/AndroidRuntime(10779): at
com.infineon.musicplayer4mNet.MusicPlayerActivity$2.run(MusicPlayerActivity.java:174)
11-26 13:32:06.727: ERROR/AndroidRuntime(10779): at
java.util.Timer$TimerImpl.run(Timer.java:284)
is pointing to the following location(Line 174). I'm using the following
code to play a user-selected song
<code snippet>
try {
mMediaPlayer.reset();
mMediaPlayer.setDataSource(filename);
mMediaPlayer.prepare();
mMediaPlayer.start();
showNotification(finalPosition);
Log.d(TAG, "duration: " + mMediaPlayer.getDuration());
mSeekBar.setMax(mMediaPlayer.getDuration());
// Keep updating the seekbar with current position
timer.schedule(new TimerTask() {
@Override
public void run() {
// TODO Auto-generated method stub
if (null != mMediaPlayer
&& mMediaPlayer.getCurrentPosition() < mMediaPlayer
.getDuration()) {
mSeekBar.setProgress(mMediaPlayer.getCurrentPosition());
}
}
}, 100, 200);
mMediaPlayer.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer arg0) {
nextSong();
}
});
} catch (Exception e) {
e.printStackTrace();
}
<code snippet>
As the error is pointing to this line
*if (null != mMediaPlayer && mMediaPlayer.getCurrentPosition() <
mMediaPlayer.getDuration())*
*
*
something is wrong here but surprisingly this is working fine on emulator
without any such error, any idea how is that possible?
Thanks for your help.
Regards,
KK
On Sat, Nov 26, 2011 at 1:21 PM, Raghav Sood <[email protected]
> wrote:
> Logcat?
>
> On Sat, Nov 26, 2011 at 1:14 PM, KK <[email protected]> wrote:
>
>> hi All,
>> I'm trying to exit the application using the following code in my
>> mediaplayer app. While it works fine in the emulator(2.2) but when I run
>> the app on an actual device (with 2.3.4 ) it gives me ANR error. Would
>> appreciate if someone can point me what is going wrong.
>>
>> ----code snippet-----
>> @Override
>> public boolean onOptionsItemSelected(MenuItem item) {
>> switch (item.getItemId()) {
>> .......
>>
>> case R.id.exit:
>> Log.d(TAG, "Shutting down the service");
>> if (mMediaPlayer != null) {
>> mMediaPlayer.release();
>> mMediaPlayer = null;
>> // remove all notifications
>> mNotificationManager.cancelAll();
>> timer.cancel();
>> finish();
>> return true;
>>
>> ....
>> ---code snippet-----
>> Just a note that I'm using notifications to show current song being
>> played, using Timer for continuously updating the seekbar for the current
>> song being played.
>>
>> Appreciate your time. Many thanks.
>>
>> Regards,
>> KK
>>
>> --
>> 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
>
>
>
>
> --
> Raghav Sood
> http://www.androidactivist.org/ - Author
> http://www.appaholics.in/ - Founder
>
> --
> 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
--
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