问题描述
首先,我想讨论中发生的情况。
First I want to discuss the scenario happening in snapchat.
当你开始录制视频并且歌曲在后台运行时,在Snapchat中;它允许在录制视频时继续播放该歌曲,在录制该视频后,您还可以在后台听到该歌曲。
In snapchat when you start recording video and song is running in background; It allows continue that song while recording video and after you record that video you can also able to hear that song in background.
我正在使用用于使用我的自定义布局录制视频和捕获图像。现在,我想做的就像上面的场景,但问题是每当我开始录制背景歌曲中的视频停止播放时。
I am using SCRecorder for recording video and capture image with my custom layout . Now in that I want to do just like above scenario but problem is whenever I start recording the video in background song is stopped playing.
SCRecorder正在使用 AVCaptureSession
用于录制视频。
SCRecorder is using AVCaptureSession
for recording video.
那么如何解决这两个问题:
So how can I resolve this two problem:
- 允许使用SCRecorder在视频中录制背景音乐。
- 录制正在视频中播放的歌曲。
推荐答案
以下是我习惯用SCRecorder库播放背景音乐的方法。
希望对您有所帮助。
Here is what i used to allow background music play with SCRecorder library.Hope this help for you too.
在 didFinishLaunchingWithOptions 方法中的 AppDelegate 类中编写此代码 -
Write this code in your AppDelegate class within didFinishLaunchingWithOptions method -
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionMixWithOthers|AVAudioSessionCategoryOptionDefaultToSpeaker|AVAudioSessionCategoryOptionAllowBluetooth error:nil];
[session setActive:YES error:nil];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
在 SCRecorder libaray'' SCRecorder.m '初始化AVCaptureSession后准备方法中的
。
After this write below line in SCRecorder libaray's 'SCRecorder.m' filewithin prepare method after initialising AVCaptureSession.
session.automaticallyConfiguresApplicationAudioSession = NO;
如果您不是SCRecorder库用户,那么在您的班级初始化AVCaptureSession之后立即写上面一行。
If you are not a SCRecorder library user, then write above line just after initialising AVCaptureSession in your class.
这篇关于允许在录制视频时播放音乐,例如snapchat ios的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!