Skip to content

Commit 26a04b3

Browse files
committed
closed #4562, fix audio resume bug after stop the music
1 parent b0e3156 commit 26a04b3

File tree

5 files changed

+18
-5
lines changed

5 files changed

+18
-5
lines changed

cocos/audio/ios/CDAudioManager.h

+1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ typedef enum {
100100
BOOL backgroundMusic;
101101
// whether background music is paused
102102
BOOL paused;
103+
BOOL stopped;
103104
@public
104105
BOOL systemPaused;//Used for auto resign handling
105106
NSTimeInterval systemPauseLocation;//Used for auto resign handling

cocos/audio/ios/CDAudioManager.m

+8-3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ -(id) init {
4848
mute = NO;
4949
enabled_ = YES;
5050
paused = NO;
51+
stopped = NO;
5152
}
5253
return self;
5354
}
@@ -96,6 +97,7 @@ -(void) play {
9697
if (enabled_) {
9798
self->systemPaused = NO;
9899
self->paused = NO;
100+
self->stopped = NO;
99101
[audioSourcePlayer play];
100102
} else {
101103
CDLOGINFO(@"Denshion::CDLongAudioSource long audio source didn't play because it is disabled");
@@ -104,6 +106,7 @@ -(void) play {
104106

105107
-(void) stop {
106108
self->paused = NO;
109+
self->stopped = YES;
107110
[audioSourcePlayer stop];
108111
}
109112

@@ -118,9 +121,11 @@ -(void) rewind {
118121
}
119122

120123
-(void) resume {
121-
self->paused = NO;
122-
[audioSourcePlayer play];
123-
}
124+
if (!stopped) {
125+
self->paused = NO;
126+
[audioSourcePlayer play];
127+
}
128+
}
124129

125130
-(BOOL) isPlaying {
126131
if (state != kLAS_Init) {

cocos/audio/mac/CDAudioManager.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ -(void) rewind {
119119

120120
-(void) resume {
121121
self->paused = NO;
122-
[audioSourcePlayer play];
122+
[audioSourcePlayer resume];
123123
}
124124

125125
-(BOOL) isPlaying {

cocos/audio/mac/CDXMacOSXSupport.h

+1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ extern OSStatus AudioSessionGetProperty(UInt32 inID, UInt32 *ioDataSize, void *o
9696
- (BOOL)playAtTime:(NSTimeInterval) time; /* play a sound some time in the future. time should be greater than deviceCurrentTime. */
9797
- (void)pause; /* pauses playback, but remains ready to play. */
9898
- (void)stop; /* stops playback. no longer ready to play. */
99+
- (BOOL) resume;
99100

100101
/* properties */
101102

cocos/audio/mac/CDXMacOSXSupport.mm

+7-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,13 @@ - (BOOL)play {
8888
result = [_player resume];
8989
}
9090
return result;
91-
}
91+
}
92+
93+
- (BOOL) resume{
94+
BOOL result = [_player resume];
95+
return result;
96+
}
97+
9298

9399
-(void) pause {
94100
[_player pause];

0 commit comments

Comments
 (0)