2013-07-04 76 views
1

我需要在用戶錄製視頻時從iPhone的主揚聲器播放音頻聲音。可能嗎?我能怎麼做? 我需要主揚聲器播放的聲音,這樣我才能在視頻中記錄這些聲音。iOS - 在錄製視頻時播放音頻/聲音

+0

您是否需要爲錄製的視頻添加聲音*或*您是否特別需要在錄製時播放聲音? – Kreiri

+0

我需要在錄製的視頻中添加聲音,而無需修改原始音頻。問題是,如果我在錄製視頻後添加聲音,我無法根據視頻@Kreiri的聲音管理正確的音量 –

回答

0

看一看this answer!

他已經使用的視頻和聲音,你想要的方式,除了路由錯了...一個答案了,有一個剪斷代碼,應該做的伎倆。

0

是的,你可以通過設置AVAudioSession類的屬性和使用AVAudioPlayer無害

設置AVAudioSession類別屬性發揮到AVAudioSessionCategoryPlayAndRecord,並設置其類別選項AVAudioSessionCategoryOptionDefaultToSpeaker|AVAudioSessionCategoryOptionMixWithOthers這將解決這個問題做。請檢查下面的代碼集

@property (strong, nonatomic) AVAudioPlayer *audioPlayer; 

NSURL *soundUrl = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"VoicemailSound" ofType:@"mp3"]]; //Download and add a system sound to your project and mention its name and type here 
self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundUrl error:nil]; 

[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker|AVAudioSessionCategoryOptionMixWithOthers error: nil]; 

[self.audioPlayer prepareToPlay]; 
[self.audioPlayer play];