gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 05:31:38 24 4
gpt4 key购买 nike

- (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];



}

它报告运行时错误:

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 库。我有同样的错误,因为文件已导入但没有将库链接到项目。

这应该可以消除您遇到的错误。

祝你有美好的一天!

关于objective-c - 在 iOS 5 中,如何使用 AudioSession 确保音频通过扬声器播放,尽管耳机已插入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9963011/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com