您的位置:首页 > 其它

OC高效率52之用前缀避免命名空间冲突

2016-02-15 00:00 489 查看
摘要: 接口与API设计

#import <Foundation/Foundation.h>
/// Apple宣称其保留使用所有“两字母前缀”的权利,自己选用的前缀应该是三个字母
@class EocSoundPlayer;
@protocol EOCSoundPlayerDelegate <NSObject>
//播放完毕回调
-(void) soundPlayerDidFinish:(EocSoundPlayer *)player;

@end

@interface EocSoundPlayer : NSObject

@property (nonatomic , weak) id <EOCSoundPlayerDelegate> delegate;

-(id) initWithURL:(NSURL *)url;
-(void) playSound;
@end

#import "EocSoundPlayer.h"
#import  <AudioToolbox/AudioToolbox.h>
void completion (SystemSoundID ssID,void *clientData)
{
EocSoundPlayer *player = (__bridge EocSoundPlayer *)clientData;

if ([player.delegate respondsToSelector:@selector(soundPlayerDidFinish:)])
{
[player.delegate soundPlayerDidFinish:player];
}
}
@implementation EocSoundPlayer
{
SystemSoundID _systemSoundID;
}

-(id)initWithURL:(NSURL *)url
{
if ((self = [super init]))
{
AudioServicesCreateSystemSoundID((__bridge CFURLRef)url, &_systemSoundID);
}
return self;
}

-(void) dealloc
{
AudioServicesDisposeSystemSoundID(_systemSoundID);
}

-(void)playSound
{
AudioServicesAddSystemSoundCompletion(_systemSoundID, NULL, NULL,completion,(__bridge void *)self), AudioServicesPlaySystemSound(_systemSoundID);

}
@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: