且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

允许在录制视频时播放音乐,例如snapchat ios

更新时间:2023-10-29 19:58:22

以下是我习惯用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' file within 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.