小智 10
1.对于此代码
AudioSessionInitialize( NULL, NULL, interruptionCallback, self );
Run Code Online (Sandbox Code Playgroud)
用...来代替
[[AVAudioSession sharedInstance] setActive:YES error:nil];
Run Code Online (Sandbox Code Playgroud)
来自这段代码
UInt32 sessionCategory = kAudioSessionCategory_PlayAndRecord;
AudioSessionSetProperty(
kAudioSessionProperty_AudioCategory,
sizeof(sessionCategory),
&sessionCategory
);
Run Code Online (Sandbox Code Playgroud)
用...来代替
UInt32 sessionCategory = kAudioSessionCategory_PlayAndRecord;
[[AVAudioSession sharedInstance]
setCategory:sessionCategory error:nil];
Run Code Online (Sandbox Code Playgroud)
小智 9
你应该使用AVAudioSession.
要替换已弃用的AudioSessionInitialize提供的功能(例如,如果需要指定AudioSessionInterruptionListener回调),可以订阅AVAudioSessionInterruptionNotification通知:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(audioSessionDidChangeInterruptionType:)
name:AVAudioSessionInterruptionNotification object:[AVAudioSession sharedInstance]];
Run Code Online (Sandbox Code Playgroud)
并实现你的audioSessionDidChangeInterruptionType:handler,如:
- (void)audioSessionDidChangeInterruptionType:(NSNotification *)notification
{
AVAudioSessionInterruptionType interruptionType = [[[notification userInfo]
objectForKey:AVAudioSessionInterruptionTypeKey] unsignedIntegerValue];
if (AVAudioSessionInterruptionTypeBegan == interruptionType)
{
}
else if (AVAudioSessionInterruptionTypeEnded == interruptionType)
{
}
}
Run Code Online (Sandbox Code Playgroud)
等效代码
// C way
UInt32 category = kAudioSessionCategory_MediaPlayback ;
OSStatus result = AudioSessionSetProperty(
kAudioSessionProperty_AudioCategory, sizeof(category), &category ) ;
if( result ) // handle the error
Run Code Online (Sandbox Code Playgroud)
是
// Objective-C way
NSError *nsError;
[[AVAudioSession sharedInstance]
setCategory:AVAudioSessionCategoryPlayback error:&nsError];
if( nsError != nil ) // handle the error
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
10659 次 |
最近记录: |