Skip to content

Commit

Permalink
Do not record when in background (to fix corrupt recordings).
Browse files Browse the repository at this point in the history
  • Loading branch information
eerimoq committed Apr 17, 2024
1 parent 7d35b0e commit f43886d
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions Moblin/Various/Model.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1048,12 +1048,18 @@ final class Model: NSObject, ObservableObject {

@objc func handleDidEnterBackgroundNotification() {
stopRtmpServer()
if isRecording {
suspendRecording()
}
}

@objc func handleWillEnterForegroundNotification() {
reloadConnections()
reloadRtmpServer()
chatTextToSpeech.reset()
if isRecording {
resumeRecording()
}
}

@objc func handleBatteryStateDidChangeNotification() {
Expand Down Expand Up @@ -1783,6 +1789,20 @@ final class Model: NSObject, ObservableObject {

func startRecording() {
setIsRecording(value: true)
resumeRecording()
makeToast(title: "Recording started")
}

func stopRecording() {
guard isRecording else {
return
}
setIsRecording(value: false)
makeToast(title: "Recording stopped")
suspendRecording()
}

func resumeRecording() {
currentRecording = recordingsStorage.createRecording(settings: stream.clone())
let bitrate = Int(stream.recording!.videoBitrate)
let keyFrameInterval = Int(stream.recording!.maxKeyFrameInterval)
Expand All @@ -1792,16 +1812,10 @@ final class Model: NSObject, ObservableObject {
videoBitrate: bitrate != 0 ? bitrate : nil,
keyFrameInterval: keyFrameInterval != 0 ? keyFrameInterval : nil
)
makeToast(title: "Recording started")
}

func stopRecording() {
guard isRecording else {
return
}
setIsRecording(value: false)
private func suspendRecording() {
media.stopRecording()
makeToast(title: "Recording stopped")
if let currentRecording {
recordingsStorage.append(recording: currentRecording)
recordingsStorage.store()
Expand Down

0 comments on commit f43886d

Please sign in to comment.