OSDN Git Service

MusicPlaybackService: catch IllegalStateException for duration and position
[android-x86/packages-apps-Eleven.git] / src / org / lineageos / eleven / MusicPlaybackService.java
index 1725234..3283f0a 100644 (file)
@@ -3396,7 +3396,12 @@ public class MusicPlaybackService extends Service {
          * @return The duration in milliseconds
          */
         public long duration() {
-            return mCurrentMediaPlayer.getDuration();
+            try {
+                return mCurrentMediaPlayer.getDuration();
+            } catch (IllegalStateException exc) {
+                Log.e(TAG, "Could not get duration", exc);
+            }
+            return 0L;
         }
 
         /**
@@ -3405,7 +3410,12 @@ public class MusicPlaybackService extends Service {
          * @return The current position in milliseconds
          */
         public long position() {
-            return mCurrentMediaPlayer.getCurrentPosition();
+            try {
+                return mCurrentMediaPlayer.getCurrentPosition();
+            } catch (IllegalStateException exc) {
+                Log.e(TAG, "Could not get current position", exc);
+            }
+            return 0L;
         }
 
         /**