From 42b24a9c5b6ad4e6374bc2850eca0ffaa784ed45 Mon Sep 17 00:00:00 2001 From: WenhaiLin Date: Mon, 7 Sep 2015 11:12:13 +0800 Subject: [PATCH] Rename AVAudioPlayer to CCAudioPlayer for avoid conflicting with system framework --- cocos/audio/mac/CDAudioManager.h | 8 ++++---- cocos/audio/mac/CDAudioManager.m | 12 ++++++------ cocos/audio/mac/CDXMacOSXSupport.h | 22 +++++++++++----------- cocos/audio/mac/CDXMacOSXSupport.mm | 2 +- cocos/audio/mac/CocosDenshion.h | 4 ++-- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/cocos/audio/mac/CDAudioManager.h b/cocos/audio/mac/CDAudioManager.h index af0ab4a98a..a7971f9251 100644 --- a/cocos/audio/mac/CDAudioManager.h +++ b/cocos/audio/mac/CDAudioManager.h @@ -90,7 +90,7 @@ typedef enum { @since v0.99 */ @interface CDLongAudioSource : NSObject { - 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). */ diff --git a/cocos/audio/mac/CDAudioManager.m b/cocos/audio/mac/CDAudioManager.m index b5365af68c..2c36961393 100644 --- a/cocos/audio/mac/CDAudioManager.m +++ b/cocos/audio/mac/CDAudioManager.m @@ -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 diff --git a/cocos/audio/mac/CDXMacOSXSupport.h b/cocos/audio/mac/CDXMacOSXSupport.h index ccab5531e7..eaa97f2e34 100644 --- a/cocos/audio/mac/CDXMacOSXSupport.h +++ b/cocos/audio/mac/CDXMacOSXSupport.h @@ -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 { +@interface CCAudioPlayer : NSObject { // properties id 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 @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 diff --git a/cocos/audio/mac/CDXMacOSXSupport.mm b/cocos/audio/mac/CDXMacOSXSupport.mm index 57fb53a715..98605d342d 100644 --- a/cocos/audio/mac/CDXMacOSXSupport.mm +++ b/cocos/audio/mac/CDXMacOSXSupport.mm @@ -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; diff --git a/cocos/audio/mac/CocosDenshion.h b/cocos/audio/mac/CocosDenshion.h index 2e40c2eaae..ccd571c0c0 100644 --- a/cocos/audio/mac/CocosDenshion.h +++ b/cocos/audio/mac/CocosDenshion.h @@ -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