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 {
|
enum SessionError {
|
||||||
case cameraNotReady = "camera-not-ready"
|
case cameraNotReady
|
||||||
|
case audioSessionSetupFailed(reason: String)
|
||||||
|
|
||||||
var code: String {
|
var code: String {
|
||||||
return rawValue
|
switch self {
|
||||||
|
case .cameraNotReady:
|
||||||
|
return "camera-not-ready"
|
||||||
|
case .audioSessionSetupFailed:
|
||||||
|
return "audio-session-setup-failed"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var message: String {
|
var message: String {
|
||||||
switch self {
|
switch self {
|
||||||
case .cameraNotReady:
|
case .cameraNotReady:
|
||||||
return "The Camera is not ready yet! Wait for the onInitialized() callback!"
|
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
|
// 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
|
// Video Input
|
||||||
do {
|
do {
|
||||||
if let videoDeviceInput = self.videoDeviceInput {
|
if let videoDeviceInput = self.videoDeviceInput {
|
||||||
|
@ -20,7 +20,7 @@ export type FormatError =
|
|||||||
| 'format/invalid-low-light-boost'
|
| 'format/invalid-low-light-boost'
|
||||||
| 'format/invalid-format'
|
| 'format/invalid-format'
|
||||||
| 'format/invalid-preset';
|
| '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 =
|
export type CaptureError =
|
||||||
| 'capture/invalid-photo-format'
|
| 'capture/invalid-photo-format'
|
||||||
| 'capture/encoder-error'
|
| 'capture/encoder-error'
|
||||||
|
Loading…
Reference in New Issue
Block a user