2

我的音频从扬声器播放,我希望它从接收器播放(带有按钮)。起初我试图强迫声音从接收器输出。(我想兼容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];

我究竟做错了什么 ?

4

1 回答 1

1

答案如下:覆盖仅适用于 kAudioSessionCategory_PlayAndRecord 类别,不适用于 AVAudioSessionCategoryPlayback。

https://developer.apple.com/library/ios/#qa/qa1754/_index.html

于 2012-11-21T08:23:49.137 回答