但仍能通过扬声器播放音频

但仍能通过扬声器播放音频

本文介绍了在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];



}

它正在报告运行时错误:

it's reporting run time error:

Undefined symbols for architecture armv7:
  "_AudioSessionSetProperty", referenced from:
      -[SoundTesterViewController viewDidLoad] in SoundTesterViewController.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)

推荐答案

请确保在xCode中包含AudioToolbox库.我遇到了同样的错误,因为文件已导入但未将库链接到项目.

Be sure to include the AudioToolbox lib in xCode. I had the same error because the files were imported but did not link the library to the project.

这应该摆脱您的错误.

祝你有美好的一天!

这篇关于在iOS 5中,如何使用AudioSession来确保尽管插入了耳机,但仍能通过扬声器播放音频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 20:34