Skip to content

Commit

Permalink
Android: handling MediaPlayer exceptions (#616)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shchvova authored Sep 2, 2023
1 parent 0feb7b4 commit 215a366
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions platform/android/sdk/src/com/ansca/corona/MediaManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,12 @@ public void playMedia( final long id, boolean loop )
}

if ( mp != null ) {
mp.setLooping(loop);

mp.start();
try {
mp.setLooping(loop);
mp.start();
} catch (Exception e) {
android.util.Log.e("Corona", "Error playing file", e);
}
} else {
Integer soundId = null;
if ( myIdToSoundPoolIdMap != null) {
Expand Down Expand Up @@ -211,7 +214,11 @@ public void stopMedia( final long id )
}

if ( mp != null ) {
mp.stop();
try {
mp.stop();
} catch (Exception e) {
android.util.Log.e("Corona", "Error while stopping player", e);
}
} else {
Integer soundId = null;
if ( myIdToSoundPoolIdMap != null) {
Expand All @@ -234,9 +241,8 @@ public void pauseMedia( final long id )
if ( mp != null ) {
try {
mp.pause();
} catch ( IllegalStateException e ) {
// #541: App crashing on exit (Android)
// happens due to exception on pause presumably due to shutdown, so ignore and continue
} catch (Exception e) {
android.util.Log.e("Corona", "Error while stopping player", e);
}
} else {
Integer soundId = null;
Expand All @@ -260,9 +266,8 @@ public void resumeMedia( final long id )
if ( mp != null ) {
try {
mp.start();
} catch ( IllegalStateException e ) {
// #541: App crashing on exit (Android)
// happens due to exception on resume if the sound has completed
} catch (Exception e) {
android.util.Log.e("Corona", "Error while stopping player", e);
}
} else {
Integer soundId = null;
Expand Down

0 comments on commit 215a366

Please sign in to comment.