Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Android: handling MediaPlayer exceptions #616

Merged
merged 1 commit into from
Sep 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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