Skip to content

Commit 9cabb54

Browse files
committed
HXMusic / HXSound: Fixed issue with enable() retaining enabled/disabled state.
1 parent 3efc96a commit 9cabb54

4 files changed

Lines changed: 20 additions & 42 deletions

File tree

apk/HXAudioPlayer_Demo.apk

-431 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 1
11-
versionName "3.1.3"
10+
versionCode 6
11+
versionName "3.1.4"
1212
}
1313
buildTypes {
1414
release {

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

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@ public class HXMusic implements HXMusicEngineListener {
1919

2020
/** CLASS VARIABLES ________________________________________________________________________ **/
2121

22+
// INSTANCE VARIABLES:
23+
private static HXMusic hxMusic; // Instance variable for HXMusic.
24+
2225
// AUDIO VARIABLES:
26+
private boolean isEnabled = true; // Used to determine if HXMusic has been enabled or disabled.
2327
private boolean isGapless; // Used to determine if gapless mode has been enabled or not.
2428
private boolean isLooped; // Used to determine if the current music has looping enabled or not.
2529
private int musicPosition; // Used for tracking the current music position.
2630
private HXMusicEngine hxMusicEngine; // Responsible for the control and playback of the MediaPlayer object.
2731
private HXMusicItem hxMusicItem; // References the current HXMusicItem that stores information about the current music.
28-
private HXMusicStatus hxMusicStatus = HXMusicStatus.NOT_READY; // Used to determine the current status of the music.
29-
30-
// INSTANCE VARIABLES:
31-
private static HXMusic hxMusic; // Instance variable for HXMusic.
32+
private HXMusicStatus hxMusicStatus = HXMusicStatus.READY; // Used to determine the current status of the music.
3233

3334
// LISTENER VARIABLES:
3435
private HXMusicListener musicListener; // Interface for listening for events from the MediaPlayer object.
@@ -43,8 +44,7 @@ private enum HXMusicStatus {
4344
READY,
4445
PLAYING,
4546
PAUSED,
46-
STOPPED,
47-
DISABLED
47+
STOPPED
4848
}
4949

5050
/** INSTANCE METHOD ________________________________________________________________________ **/
@@ -96,7 +96,7 @@ public synchronized void initMusic(HXMusicItem music, int position, boolean isGa
9696
// specified music can be played or not.
9797
private boolean checkStatus(HXMusicItem music) {
9898

99-
if (hxMusicStatus.equals(HXMusicStatus.DISABLED)) {
99+
if (!isEnabled) {
100100
HXLog.e(LOG_TAG, "ERROR: checkStatus(): Music has been currently disabled.");
101101
return false;
102102
} else if (music == null) {
@@ -232,12 +232,7 @@ public static void clear() {
232232
// enable(): Used for enabling and disabling music playback.
233233
public static void enable(boolean isEnabled) {
234234
instance();
235-
236-
if (isEnabled) {
237-
hxMusic.hxMusicStatus = HXMusicStatus.READY;
238-
} else {
239-
hxMusic.hxMusicStatus = HXMusicStatus.DISABLED;
240-
}
235+
hxMusic.isEnabled = isEnabled;
241236
}
242237

243238
// getPosition(): Returns the current music position.

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

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ public class HXSound {
2323
private static HXSound hxSound; // HXSound instance variable.
2424

2525
// AUDIO VARIABLES:
26-
//private boolean isEnabled; // Used for determining if the sound system is enabled or not.
26+
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.READY; // Used to determine the current status of the sound system.
3029
private LinkedList<HXSoundEngine> hxSoundEngines; // LinkedList object which contains the HXSoundEngine instances.
3130

3231
// CONSTANT VARIABLES:
@@ -36,13 +35,6 @@ public class HXSound {
3635
// LOGGING VARIABLES:
3736
private static final String LOG_TAG = HXSound.class.getSimpleName();
3837

39-
/** ENUM ___________________________________________________________________________________ **/
40-
41-
private enum HXSoundStatus {
42-
READY,
43-
DISABLED
44-
}
45-
4638
/** INSTANCE METHOD ________________________________________________________________________ **/
4739

4840
// instance(): Returns the hxSound instance.
@@ -90,7 +82,6 @@ private void initializeSoundEngines() {
9082
i++;
9183
}
9284

93-
hxSoundStatus = HXSoundStatus.READY;
9485
HXLog.d(LOG_TAG, "BUILD: All HXSoundEngines are ready.");
9586
}
9687

@@ -126,7 +117,7 @@ public synchronized boolean playSoundFx(int resource, boolean isLooped, Context
126117
return false;
127118
}
128119

129-
if (!hxSoundStatus.equals(HXSoundStatus.DISABLED)) {
120+
if (isEnabled) {
130121

131122
if (hxSoundEngines == null) {
132123
initializeSoundEngines();
@@ -195,7 +186,7 @@ public static void resumeSounds() {
195186
// clear(): Releases resources held by this singleton and other objects associated with this
196187
// object. This method should be called when the singleton object is no longer in use.
197188
public static void clear() {
198-
if (hxSound != null) {
189+
if (hxSound != null && hxSound.hxSoundEngines != null) {
199190
hxSound.release();
200191
hxSound = null;
201192
}
@@ -204,12 +195,7 @@ public static void clear() {
204195
// enable(): Used to enable or disable the HXSound system.
205196
public static void enable(boolean isEnabled) {
206197
instance();
207-
208-
if (isEnabled) {
209-
hxSound.hxSoundStatus = HXSoundStatus.READY;
210-
} else {
211-
hxSound.hxSoundStatus = HXSoundStatus.DISABLED;
212-
}
198+
hxSound.isEnabled = isEnabled;
213199
}
214200

215201
// engines(): Specifies the number of sound engine instances to be enabled. This feature is only
@@ -241,15 +227,12 @@ private void release() {
241227
HXLog.d(LOG_TAG, "RELEASE: release(): Releasing all HXSoundEngine instances...");
242228

243229
// Releases all HXSoundEngine instances.
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;
230+
int i = 0;
231+
for (int x : new int[numberOfEngines]) {
232+
hxSoundEngines.get(i).release();
233+
HXLog.d(LOG_TAG, "RELEASE: release(): HXSoundEngine (" + i + ") is released.");
234+
i++;
252235
}
253-
hxSound = null;
236+
hxSoundEngines = null;
254237
}
255238
}

0 commit comments

Comments
 (0)