Rename AVAudioPlayer to CCAudioPlayer for avoid conflicting with system framework

This commit is contained in:
WenhaiLin 2015-09-07 11:12:13 +08:00
parent 70d551a932
commit 42b24a9c5b
5 changed files with 24 additions and 24 deletions

View File

@ -90,7 +90,7 @@ typedef enum {
@since v0.99
*/
@interface CDLongAudioSource : NSObject <AVAudioPlayerDelegate, CDAudioInterruptProtocol>{
AVAudioPlayer *audioSourcePlayer;
CCAudioPlayer *audioSourcePlayer;
NSString *audioSourceFilePath;
NSInteger numberOfLoops;
float volume;
@ -106,7 +106,7 @@ typedef enum {
@protected
tLongAudioSourceState state;
}
@property (readonly) AVAudioPlayer *audioSourcePlayer;
@property (readonly) CCAudioPlayer *audioSourcePlayer;
@property (readonly) NSString *audioSourceFilePath;
@property (readwrite, nonatomic) NSInteger numberOfLoops;
@property (readwrite, nonatomic) float volume;
@ -196,13 +196,13 @@ typedef enum {
/** Call if you want to use built in resign behavior but need to do some additional audio processing on become active. */
- (void) applicationDidBecomeActive;
//New AVAudioPlayer API
//New CCAudioPlayer API
/** Loads the data from the specified file path to the channel's audio source */
-(CDLongAudioSource*) audioSourceLoad:(NSString*) filePath channel:(tAudioSourceChannel) channel;
/** Retrieves the audio source for the specified channel */
-(CDLongAudioSource*) audioSourceForChannel:(tAudioSourceChannel) channel;
//Legacy AVAudioPlayer API
//Legacy CCAudioPlayer API
/** Plays music in background. The music can be looped or not
It is recommended to use .aac files as background music since they are decoded by the device (hardware).
*/

View File

@ -66,12 +66,12 @@ NSString * const kCDN_AudioManagerInitialised = @"kCDN_AudioManagerInitialised";
//New file
if (state != kLAS_Init) {
[audioSourceFilePath release];//Release old file path
[audioSourcePlayer release];//Release old AVAudioPlayer, they can't be reused
[audioSourcePlayer release];//Release old CCAudioPlayer, they can't be reused
}
audioSourceFilePath = [filePath copy];
NSError *error = nil;
NSString *path = [CDUtilities fullPathFromRelativePath:audioSourceFilePath];
audioSourcePlayer = [(AVAudioPlayer*)[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:&error];
audioSourcePlayer = [(CCAudioPlayer*)[CCAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:&error];
if (error == nil) {
[audioSourcePlayer prepareToPlay];
audioSourcePlayer.delegate = self;
@ -190,12 +190,12 @@ NSString * const kCDN_AudioManagerInitialised = @"kCDN_AudioManagerInitialised";
numberOfLoops = loopCount;
}
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag {
- (void)audioPlayerDidFinishPlaying:(CCAudioPlayer *)player successfully:(BOOL)flag {
CDLOGINFO(@"Denshion::CDLongAudioSource - audio player finished");
#if TARGET_IPHONE_SIMULATOR
CDLOGINFO(@"Denshion::CDLongAudioSource - workaround for OpenAL clobbered audio issue");
//This is a workaround for an issue in all simulators (tested to 3.1.2). Problem is
//that OpenAL audio playback is clobbered when an AVAudioPlayer stops. Workaround
//that OpenAL audio playback is clobbered when an CCAudioPlayer stops. Workaround
//is to keep the player playing on an endless loop with 0 volume and then when
//it is played again reset the volume and set loop count appropriately.
//NB: this workaround is not foolproof but it is good enough for most situations.
@ -208,11 +208,11 @@ NSString * const kCDN_AudioManagerInitialised = @"kCDN_AudioManagerInitialised";
}
}
-(void)audioPlayerBeginInterruption:(AVAudioPlayer *)player {
-(void)audioPlayerBeginInterruption:(CCAudioPlayer *)player {
CDLOGINFO(@"Denshion::CDLongAudioSource - audio player interrupted");
}
-(void)audioPlayerEndInterruption:(AVAudioPlayer *)player {
-(void)audioPlayerEndInterruption:(CCAudioPlayer *)player {
CDLOGINFO(@"Denshion::CDLongAudioSource - audio player resumed");
if (self.backgroundMusic) {
//Check if background music can play as rules may have changed during

View File

@ -23,13 +23,13 @@
*/
/**
A set of proxy classes to allow iOS audio code to run on MacOS X. AVAudioPlayer is implemented using NSSound.
A set of proxy classes to allow iOS audio code to run on MacOS X. CCAudioPlayer is implemented using NSSound.
AVAudioSession is a "do nothing" class as it isn't really relevant on MacOS X.
Limitations:
AVAudioPlayer numberOfLoops not correctly supported. Looping is either on or off, can not specify a specific number of loops.
AVAudioPlayer panning not supported.
AVAudioPlayer metering not supported.
CCAudioPlayer numberOfLoops not correctly supported. Looping is either on or off, can not specify a specific number of loops.
CCAudioPlayer panning not supported.
CCAudioPlayer metering not supported.
AVAudioSession nothing is supported, not applicable to MacOS X.
*/
@ -60,7 +60,7 @@ extern OSStatus AudioSessionGetProperty(UInt32 inID, UInt32 *ioDataSize, void *o
@protocol AVAudioPlayerDelegate;
/* This class is available with iPhone 2.2 or later */
@interface AVAudioPlayer : NSObject <NSSoundDelegate> {
@interface CCAudioPlayer : NSObject <NSSoundDelegate> {
// properties
id<AVAudioPlayerDelegate> delegate;
@ -137,24 +137,24 @@ extern OSStatus AudioSessionGetProperty(UInt32 inID, UInt32 *ioDataSize, void *o
@end
/* A protocol for delegates of AVAudioPlayer */
/* A protocol for delegates of CCAudioPlayer */
@protocol AVAudioPlayerDelegate <NSObject>
@optional
/* audioPlayerDidFinishPlaying:successfully: is called when a sound has finished playing. This method is NOT called if the player is stopped due to an interruption. */
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag;
- (void)audioPlayerDidFinishPlaying:(CCAudioPlayer *)player successfully:(BOOL)flag;
/* if an error occurs while decoding it will be reported to the delegate. */
- (void)audioPlayerDecodeErrorDidOccur:(AVAudioPlayer *)player error:(NSError *)error;
- (void)audioPlayerDecodeErrorDidOccur:(CCAudioPlayer *)player error:(NSError *)error;
/* audioPlayerBeginInterruption: is called when the audio session has been interrupted while the player was playing. The player will have been paused. */
- (void)audioPlayerBeginInterruption:(AVAudioPlayer *)player;
- (void)audioPlayerBeginInterruption:(CCAudioPlayer *)player;
/* audioPlayerEndInterruption:withFlags: is called when the audio session interruption has ended and this player had been interrupted while playing. */
/* Currently the only flag is AVAudioSessionInterruptionFlags_ShouldResume. */
- (void)audioPlayerEndInterruption:(AVAudioPlayer *)player withFlags:(NSUInteger)flags;
- (void)audioPlayerEndInterruption:(CCAudioPlayer *)player withFlags:(NSUInteger)flags;
/* audioPlayerEndInterruption: is called when the preferred method, audioPlayerEndInterruption:withFlags:, is not implemented. */
- (void)audioPlayerEndInterruption:(AVAudioPlayer *)player;
- (void)audioPlayerEndInterruption:(CCAudioPlayer *)player;
@end

View File

@ -42,7 +42,7 @@ OSStatus AudioSessionGetProperty(UInt32 inID, UInt32 *ioDataSize, void *outData)
return 0;
}
@implementation AVAudioPlayer
@implementation CCAudioPlayer
@synthesize delegate, numberOfChannels, pan, deviceCurrentTime, url, data;

View File

@ -41,12 +41,12 @@ Requirements:
- Frameworks: OpenAL, AudioToolbox, AVFoundation
@par CDAudioManager
CDAudioManager is basically a thin wrapper around an AVAudioPlayer object used for playing
CDAudioManager is basically a thin wrapper around an CCAudioPlayer object used for playing
background music and a CDSoundEngine object used for playing sound effects. It manages the
audio session for you deals with audio session interruption. It is fairly low level and it
is expected you have some understanding of the underlying technologies. For example, for
many use cases regarding background music it is expected you will work directly with the
backgroundMusic AVAudioPlayer which is exposed as a property.
backgroundMusic CCAudioPlayer which is exposed as a property.
Requirements:
- Firmware: OS 2.2 or greater