Allows music playback during recording video like snapchat ios

好久不见. 提交于 2019-12-18 10:56:24

问题


First I want to discuss the scenario happening in 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 is using AVCaptureSession for recording video.

So how can I resolve this two problem:

  1. Allow background music whiile recording in video using SCRecorder.
  2. Record song that is playing in background in video .

回答1:


Here is what i used to allow background music play with SCRecorder library. Hope this help for you too.

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

After this write below line in SCRecorder libaray's 'SCRecorder.m' file within prepare method after initialising AVCaptureSession.

session.automaticallyConfiguresApplicationAudioSession = NO;

If you are not a SCRecorder library user, then write above line just after initialising AVCaptureSession in your class.



来源:https://stackoverflow.com/questions/28715597/allows-music-playback-during-recording-video-like-snapchat-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!