IOS开发基础之音频工具类封装AVAudioPlayer
源码在我的主页下面 ,项目名称是AVAudioPlayer
关键性代码
工具类的封装
//
// LJAudioTool.h
// AVAudioPlayer
//
// Created by 鲁军 on 2021/4/23.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface LJAudioTool : NSObject
+(BOOL)playMusic:(NSString*)filename;
+(void)pauseMusic:(NSString*)filename;
+(void)stopMusic:(NSString*)filename;
+(void)playSound:(NSString*)filename;
+(void)disposeSound:(NSString*)filename;
@end
NS_ASSUME_NONNULL_END
//
// LJAudioTool.m
// AVAudioPlayer
//
// Created by 鲁军 on 2021/4/23.
//
#import "LJAudioTool.h"
#import <AVFoundation/AVFoundation.h>
@implementation LJAudioTool
static NSMutableDictionary *_soundIDs;
+(NSMutableDictionary *)soundIDs{
if(!_soundIDs){
_soundIDs = [NSMutableDictionary dictionary];
}
return _soundIDs;
}
+(void)playSound:(NSString*)filename{
if(