Tag: 设施

MPMediaItem不使用MPMediaItemPropertyAssetURL在AVAudioPlayer中播放

我有这个代码,find并播放MPMediaItem: MPMediaPropertyPredicate *predicate = [MPMediaPropertyPredicate predicateWithValue:self.persistentIDOfSongToPlay forProperty:MPMediaItemPropertyPersistentID comparisonType:MPMediaPredicateComparisonContains]; NSSet *predicateSet = [NSSet setWithObject:predicate]; MPMediaQuery *searchQuery = [[MPMediaQuery alloc] initWithFilterPredicates:predicateSet]; NSArray *queryResults = [searchQuery items]; NSLog(@"count: %i", queryResults.count); MPMediaItem *item = [queryResults objectAtIndex:0]; NSLog(@"item: %@", item); NSURL *itemURL = [item valueForProperty:MPMediaItemPropertyAssetURL]; NSLog(@"url: %@", itemURL); NSError *error; AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:itemURL error:&error]; [audioPlayer prepareToPlay]; [audioPlayer […]

AVCaptureSession的addInput导致后台audio出现毛刺

我正在制作一个video捕捉iOS应用程序,我希望能够从麦克风录制audio,同时允许播放背景音乐。 我可以做所有这些,但是只要相机的视图进入并退出前景,背景audio就会跳过(暂停一下)。 我已经隔离了AVCaptureSession addInput错误: AVCaptureSession session = [[AVCaptureSession alloc] init]; session.automaticallyConfiguresApplicationAudioSession = NO; AVCaptureDevice *audioDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio]; AVCaptureDeviceInput *audioDeviceInput = [AVCaptureDeviceInput deviceInputWithDevice:audioDevice error:nil]; // this line causes the background music to skip [session addInput:audioDeviceInput]; 如何防止添加麦克风input影响背景audio? fyi – 在didFinishLaunchingWithOptions我设置AVAudioSession类别: [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionMixWithOthers | AVAudioSessionCategoryOptionDefaultToSpeaker error:nil];

AVAudioSession AVAudioSessionCategoryPlayAndRecord毛刺

我想使用AVCaptureSession录制带有audio的video。 为此我需要AudioSessionCategory AVAudioSessionCategoryPlayAndRecord ,因为我的应用程序还播放有声video。 我希望audio能够从默认扬声器中听到,我希望它能与其他audio混合。 所以我需要选项AVAudioSessionCategoryOptionDefaultToSpeaker | AVAudioSessionCategoryOptionMixWithOthers AVAudioSessionCategoryOptionDefaultToSpeaker | AVAudioSessionCategoryOptionMixWithOthers 。 如果我在播放其他audio时进行以下操作,则会从另一个应用程序的audio中看到清晰的声音故障: [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionMixWithOthers | AVAudioSessionCategoryOptionDefaultToSpeaker error:nil]; [[AVAudioSession sharedInstance] setActive:YES error:nil]; 有没有办法摆脱这个故障? 当AVAudioSessionRouteChangeReasonCategoryChange从没有话筒input到话筒input时, AVAudioSessionRouteChangeReasonRouteConfigurationChange通知AVAudioSessionRouteChangeReasonCategoryChange 。 应用程序转到后台时(也可以不closuresaudio会话)也会发生configuration更改(和毛刺)。 在不closuresaudio会话的情况下从后台返回时,当AVCaptureSessionconfiguration发生变化,即相机从前向后切换时,会出现毛刺。 在这种情况下,audio路由不被触摸,并且仅在从后台返回而不closuresaudio会话时发生。 路由改变的通知被激发两次。 一次禁用麦克风,一次再次启用。 请注意,通过下载Apple的AVCamManual示例,可以很容易地重现此行为。 将以下内容添加到AAPLCameraViewController.m的viewDidLoad中: [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionMixWithOthers | AVAudioSessionCategoryOptionDefaultToSpeaker error:nil]; [[AVAudioSession sharedInstance] setActive:YES error:nil]; … session.usesApplicationAudioSession = YES; session.automaticallyConfiguresApplicationAudioSession = NO; 其他一些奇怪的事情,这可能是相关的: 首先将audio类别设置为AVAudioSessionCategoryAmbient并将其激活: […]

AVSpeechSynthesizer错误AudioSession

我正在玩AVSpeechSynthesizer,总是得到这些错误: ERROR: >aqsrv> 65: Exception caught in (null) – error -66634 ERROR: AVAudioSessionUtilities.h:88: GetProperty_DefaultToZero: AudioSessionGetProperty ('disa') failed with error: '?ytp' 我的代码是: AVSpeechSynthesizer *synthesizer = [[AVSpeechSynthesizer alloc] init]; [synthesizer setDelegate:self]; speechSpeed = AVSpeechUtteranceMinimumSpeechRate; AVSpeechUtterance *synUtt = [[AVSpeechUtterance alloc] initWithString:[[self text] text]]; [synUtt setRate:speechSpeed]; [synUtt setVoice:[AVSpeechSynthesisVoice voiceWithLanguage:languageCode]]; [synthesizer speakUtterance:synUtt]; 有谁知道如何解决这些错误?