#import "MyAudioManager.h"
#import <AVFoundation/AVFoundation.h>
#import "NSStringEx.h"
@interface MyAudioManager()<AVAudioPlayerDelegate>
@property (nonatomic, strong) AVAudioSession *session;
@property (nonatomic, strong) AVAudioPlayer *player;
@property (nonatomic, strong) AVAudioRecorder *recorder;
@property (nonatomic, strong) NSURL *recordFileURL;
@property (nonatomic, copy) NSString *recordUrlKey;
@property (nonatomic, copy) didPlayFinish finishBlock;
@end
@implementation MyAudioManager
+ (instancetype)sharedInstance
{
static MyAudioManager *_sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_sharedInstance = [[self alloc ] init];
[_sharedInstance setproximity];
});
return _sharedInstance;
}
#pragma mark --设置距离传感器
- (void)setproximity{
self.session = [AVAudioSession sharedInstance];
NSError *sessionError = nil;
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
AudioSessionSetProperty (
kAudioSessionProperty_OverrideAudioRoute,
sizeof (audioRouteOverride),
&audioRouteOverride
);
UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory,