Skip to content

Commit 3efc96a

Browse files
committed
HXSound: Fixed null pointer issue when releasing audio.
1 parent f33e5a1 commit 3efc96a

4 files changed

Lines changed: 24 additions & 16 deletions

File tree

apk/HXAudioPlayer_Demo.apk

5 Bytes
Binary file not shown.

app/app.iml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,24 @@
7878
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
7979
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
8080
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
81+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/builds" />
8182
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
8283
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
84+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-classes" />
85+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-runtime-classes" />
8386
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-safeguard" />
87+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-verifier" />
88+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-resources" />
89+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-support" />
8490
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
8591
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
8692
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
93+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/reload-dex" />
8794
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
95+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/restart-dex" />
8896
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
8997
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" />
98+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/split-apk" />
9099
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
91100
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
92101
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />

hxaudio/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ android {
88
minSdkVersion 9
99
targetSdkVersion 25
1010
versionCode 1
11-
versionName "3.1.2"
11+
versionName "3.1.3"
1212
}
1313
buildTypes {
1414
release {

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

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class HXSound {
2626
//private boolean isEnabled; // Used for determining if the sound system is enabled or not.
2727
private int currentEngine; // Used for determining the active HXSoundEngine instance.
2828
private int numberOfEngines; // Used for determining the number of HXSoundEngine instances.
29-
private HXSoundStatus hxSoundStatus = HXSoundStatus.NOT_READY; // Used to determine the current status of the sound system.
29+
private HXSoundStatus hxSoundStatus = HXSoundStatus.READY; // Used to determine the current status of the sound system.
3030
private LinkedList<HXSoundEngine> hxSoundEngines; // LinkedList object which contains the HXSoundEngine instances.
3131

3232
// CONSTANT VARIABLES:
@@ -39,9 +39,7 @@ public class HXSound {
3939
/** ENUM ___________________________________________________________________________________ **/
4040

4141
private enum HXSoundStatus {
42-
NOT_READY,
4342
READY,
44-
RELEASED,
4543
DISABLED
4644
}
4745

@@ -128,12 +126,12 @@ public synchronized boolean playSoundFx(int resource, boolean isLooped, Context
128126
return false;
129127
}
130128

131-
if (hxSoundStatus.equals(HXSoundStatus.NOT_READY) || hxSoundStatus.equals(HXSoundStatus.RELEASED)) {
132-
initializeSoundEngines();
133-
}
134-
135129
if (!hxSoundStatus.equals(HXSoundStatus.DISABLED)) {
136130

131+
if (hxSoundEngines == null) {
132+
initializeSoundEngines();
133+
}
134+
137135
HXLog.d(LOG_TAG, "SOUND: Attempting to play sound effect on HXSoundEngine (" + currentEngine + ")...");
138136
hxSoundEngines.get(currentEngine).prepareSoundFx(resource, isLooped, context);
139137

@@ -243,14 +241,15 @@ private void release() {
243241
HXLog.d(LOG_TAG, "RELEASE: release(): Releasing all HXSoundEngine instances...");
244242

245243
// Releases all HXSoundEngine instances.
246-
int i = 0;
247-
for (int x : new int[numberOfEngines]) {
248-
hxSoundEngines.get(i).release();
249-
HXLog.d(LOG_TAG, "RELEASE: release(): HXSoundEngine (" + i + ") is released.");
250-
i++;
244+
if (hxSoundEngines != null) {
245+
int i = 0;
246+
for (int x : new int[numberOfEngines]) {
247+
hxSoundEngines.get(i).release();
248+
HXLog.d(LOG_TAG, "RELEASE: release(): HXSoundEngine (" + i + ") is released.");
249+
i++;
250+
}
251+
hxSoundEngines = null;
251252
}
252-
253-
hxSoundEngines = null;
254-
hxSoundStatus = HXSoundStatus.RELEASED;
253+
hxSound = null;
255254
}
256255
}

0 commit comments

Comments
 (0)