HKStreamRecorder

public actor HKStreamRecorder
extension HKStreamRecorder: HKStreamOutput
extension HKStreamRecorder: MediaMixerOutput

An actor represents video and audio recorder.

This actor is compatible with both HKStreamOutput and MediaMixerOutput. This means it can record the output from MediaMixer in addition to HKStream.

 // An example of recording MediaMixer.
 let recorder = HKStreamRecorder()
 let mixer = MediaMixer()
 mixer.addOutput(recorder)
 // An example of recording streaming.
 let recorder = HKStreamRecorder()
 let mixer = MediaMixer()
 let stream = RTMPStream()
 mixer.addOutput(stream)
 stream.addOutput(recorder)
  • The error domain codes.

    See more

    Declaration

    Swift

    public enum Error : Swift.Error
  • The default recording settings.

    Declaration

    Swift

    public static let defaultSettings: [AVMediaType : [String : any Sendable]]
  • The recorder settings.

    Declaration

    Swift

    public private(set) var settings: [AVMediaType : [String : any Sendable]] { get }
  • The recording file name.

    Declaration

    Swift

    public private(set) var fileName: String? { get }
  • The recording or not.

    Declaration

    Swift

    public private(set) var isRecording: Bool { get }
  • The the movie fragment interval in sec.

    Declaration

    Swift

    public private(set) var movieFragmentInterval: Double? { get }
  • Declaration

    Swift

    public private(set) var videoTrackId: UInt8? { get }
  • Declaration

    Swift

    public private(set) var audioTrackId: UInt8? { get }
  • Creates a new recorder.

    Declaration

    Swift

    public init()
  • Sets the movie fragment interval in sec.

    This value allows the file to be written continuously, so the file will remain even if the app crashes or is forcefully terminated. A value of 10 seconds or more is recommended.

    Declaration

    Swift

    public func setMovieFragmentInterval(movieFragmentInterval: Double?)
  • Starts recording.

    Declaration

    Swift

    public func startRecording(_ filaName: String? = nil, settings: [AVMediaType : [String : any Sendable]] = HKStreamRecorder.defaultSettings) async throws
  • stopRecording() Asynchronous

    Stops recording.

    Example of saving to the Photos app.

     do {
       let outputURL = try await recorder.stopRecording()
       PHPhotoLibrary.shared().performChanges({() -> Void in
         PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: outputURL)
       }, completionHandler: { _, error -> Void in
         try? FileManager.default.removeItem(at: outputURL)
       }
     } catch {
        print(error)
     }
    

    Declaration

    Swift

    public func stopRecording() async throws -> URL
  • Declaration

    Swift

    public func selectTrack(_ id: UInt8?, mediaType: CMFormatDescription.MediaType)

HKStreamOutput

MediaMixerOutput