Manually setup AVAudioSession (allow background music playback)
This commit is contained in:
parent
bcdf30fa9d
commit
49e5dd67dc
@ -133,17 +133,25 @@ enum FormatError {
|
||||
}
|
||||
}
|
||||
|
||||
enum SessionError: String {
|
||||
case cameraNotReady = "camera-not-ready"
|
||||
enum SessionError {
|
||||
case cameraNotReady
|
||||
case audioSessionSetupFailed(reason: String)
|
||||
|
||||
var code: String {
|
||||
return rawValue
|
||||
switch self {
|
||||
case .cameraNotReady:
|
||||
return "camera-not-ready"
|
||||
case .audioSessionSetupFailed:
|
||||
return "audio-session-setup-failed"
|
||||
}
|
||||
}
|
||||
|
||||
var message: String {
|
||||
switch self {
|
||||
case .cameraNotReady:
|
||||
return "The Camera is not ready yet! Wait for the onInitialized() callback!"
|
||||
case let .audioSessionSetupFailed(reason):
|
||||
return "The audio session failed to setup! \(reason)"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -228,6 +228,16 @@ final class CameraView: UIView {
|
||||
}
|
||||
|
||||
// INPUTS
|
||||
// Audio Setup
|
||||
do {
|
||||
captureSession.automaticallyConfiguresApplicationAudioSession = false
|
||||
try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playAndRecord, options: [.mixWithOthers, .allowBluetooth, .defaultToSpeaker])
|
||||
try AVAudioSession.sharedInstance().setActive(true)
|
||||
} catch let error as NSError {
|
||||
// not critical, so don't return
|
||||
invokeOnError(.session(.audioSessionSetupFailed(reason: error.description)))
|
||||
}
|
||||
|
||||
// Video Input
|
||||
do {
|
||||
if let videoDeviceInput = self.videoDeviceInput {
|
||||
|
@ -20,7 +20,7 @@ export type FormatError =
|
||||
| 'format/invalid-low-light-boost'
|
||||
| 'format/invalid-format'
|
||||
| 'format/invalid-preset';
|
||||
export type SessionError = 'session/camera-not-ready';
|
||||
export type SessionError = 'session/camera-not-ready' | 'session/audio-session-setup-failed';
|
||||
export type CaptureError =
|
||||
| 'capture/invalid-photo-format'
|
||||
| 'capture/encoder-error'
|
||||
|
Loading…
Reference in New Issue
Block a user