Skip to content

Commit 67e661f

Browse files
committed
HXMusicEngine: Resolved IllegalStateException issues with nextPlayer MediaPlayer object.
1 parent 9cabb54 commit 67e661f

3 files changed

Lines changed: 20 additions & 10 deletions

File tree

apk/HXAudioPlayer_Demo.apk

97 Bytes
Binary file not shown.

hxaudio/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ android {
77
defaultConfig {
88
minSdkVersion 9
99
targetSdkVersion 25
10-
versionCode 6
11-
versionName "3.1.4"
10+
versionCode 7
11+
versionName "3.1.5"
1212
}
1313
buildTypes {
1414
release {

hxaudio/src/main/java/com/huhx0015/hxaudio/audio/HXMusicEngine.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,18 @@ public void onPrepared(MediaPlayer currentPlayer) {
8888
HXLog.d(LOG_TAG, "PREPARING: onPrepared(): MediaPlayer looping status: " + isLooped);
8989
}
9090

91-
currentPlayer.start(); // Begins playing the music.
91+
try {
92+
currentPlayer.start(); // Begins playing the music.
9293

93-
// Invokes the associated listener call.
94-
if (musicEngineListener != null) {
95-
musicEngineListener.onMusicEnginePrepared();
96-
}
94+
// Invokes the associated listener call.
95+
if (musicEngineListener != null) {
96+
musicEngineListener.onMusicEnginePrepared();
97+
}
9798

98-
HXLog.d(LOG_TAG, "MUSIC: onPrepared(): Music playback has begun.");
99+
HXLog.d(LOG_TAG, "MUSIC: onPrepared(): Music playback has begun.");
100+
} catch (Exception e) {
101+
HXLog.e(LOG_TAG, "ERROR: onPrepared(): " + e.getLocalizedMessage());
102+
}
99103
}
100104
});
101105

@@ -181,8 +185,14 @@ else if (musicItem.getMusicResource() != 0) {
181185
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
182186
@Override
183187
public void onPrepared(MediaPlayer mp) {
184-
currentPlayer.setNextMediaPlayer(nextPlayer);
185-
currentPlayer.setOnCompletionListener(nextPlayerCompletionListener);
188+
try {
189+
if (currentPlayer != null && nextPlayer != null) {
190+
currentPlayer.setNextMediaPlayer(nextPlayer);
191+
currentPlayer.setOnCompletionListener(nextPlayerCompletionListener);
192+
}
193+
} catch (Exception e) {
194+
HXLog.e(LOG_TAG, "ERROR: onPrepared(): " + e.getLocalizedMessage());
195+
}
186196
}
187197
};
188198

0 commit comments

Comments
 (0)