From 215a366030b1e3c712096999a8b15f9c0f181a9a Mon Sep 17 00:00:00 2001 From: Vlad Svoka Date: Sat, 2 Sep 2023 09:46:39 -0700 Subject: [PATCH] Android: handling MediaPlayer exceptions (#616) --- .../src/com/ansca/corona/MediaManager.java | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/platform/android/sdk/src/com/ansca/corona/MediaManager.java b/platform/android/sdk/src/com/ansca/corona/MediaManager.java index 19b525dfe..e60c66958 100644 --- a/platform/android/sdk/src/com/ansca/corona/MediaManager.java +++ b/platform/android/sdk/src/com/ansca/corona/MediaManager.java @@ -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) { @@ -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) { @@ -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; @@ -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;