小编use*_*150的帖子

在iOS 5中,如何使用AudioSession确保通过扬声器播放音频,但耳机已插入?

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"1" 
                                                         ofType:@"mp3"];

    // Convert the file path to a URL.
    NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:filePath];
    [[AVAudioSession sharedInstance] setDelegate: self];


    UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
    AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride);

    //Initialize the AVAudioPlayer.
    self.audioPlayer = [[AVAudioPlayer alloc] 
                        initWithContentsOfURL:fileURL error:nil];
    self.audioPlayer.volume = 1.0;

    // Preloads the buffer and prepares the audio for playing.
    [self.audioPlayer prepareToPlay];



}
Run Code Online (Sandbox Code Playgroud)

它的报告运行时错误:

Undefined symbols for architecture armv7:
  "_AudioSessionSetProperty", referenced from:
      -[SoundTesterViewController viewDidLoad] in SoundTesterViewController.o
ld: symbol(s) not found for …
Run Code Online (Sandbox Code Playgroud)

objective-c ios ios5

4
推荐指数
1
解决办法
1131
查看次数

标签 统计

ios ×1

ios5 ×1

objective-c ×1