我的音频从扬声器播放,我希望它从接收器播放(带有按钮)。起初我试图强迫声音从接收器输出。(我想兼容iOS 3.2)
这是我在 [super viewDidLoad] 之后的内容;
[[AVAudioSession sharedInstance] setDelegate: self];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error: nil];
// UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_None;
AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride);
[[AVAudioSession sharedInstance] setActive:YES error:nil];
后来当我打电话时:
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:lblText.text
ofType:@"mp3"]];
NSError *error;
audioPlayer = [[AVAudioPlayer alloc]
initWithContentsOfURL:url
error:&error];
if (error)
{
NSLog(@"Error in audioPlayer: %@",
[error localizedDescription]);
} else {
audioPlayer.delegate = self;
}
[self playAudio];
MPVolumeView *volumeView = [[[MPVolumeView alloc] initWithFrame:[volumeSlider frame]] autorelease];
[volumeSlider removeFromSuperview];
[self.view addSubview:volumeView];
我究竟做错了什么 ?