VKRecorderSession
@objc
public class VKRecorderSession : NSObject
VKRecorderSession, a powerful object for managing and editing a set of recorded media clips.
-
Declaration
Swift
public weak var delegate: VKRecorderDelegate?
-
Output directory for a session.
Declaration
Swift
public var outputDirectory: String
-
Output file type for a session, see AVMediaFormat.h for supported types.
Declaration
Swift
public var fileType: AVFileType
-
Output file extension for a session, see AVMediaFormat.h for supported extensions.
Declaration
Swift
public var fileExtension: String
-
Unique identifier for a session.
Declaration
Swift
public var videoID: UUID { get }
-
Creation date for a session.
Declaration
Swift
public var date: Date { get }
-
Declaration
Swift
public var state: VKRecordingState
-
Declaration
Swift
public enum VKRecordingState
-
Creates a URL for session output, otherwise nil
Declaration
Swift
public var url: URL? { get }
-
Declaration
Swift
public var isVideoSetup: Bool { get }
-
Checks if the session is setup for recording video
Declaration
Swift
public var isVideoReady: Bool { get }
-
Declaration
Swift
public var isAudioSetup: Bool { get }
-
Checks if the session is setup for recording audio
Declaration
Swift
public var isAudioReady: Bool { get }
-
Recorded clips for the session.
Declaration
Swift
public var clips: [VKRecorderClip] { get }
-
Duration of a session, the sum of all recorded clips.
Declaration
Swift
public var totalDuration: CMTime { get }
-
Checks if the session’s asset writer is ready for data.
Declaration
Swift
public var isWriterReady: Bool { get }
-
True if the current clip recording has been started.
Declaration
Swift
public var currentClipHasStarted: Bool { get }
-
Duration of the current clip.
Declaration
Swift
public var currentClipDuration: CMTime { get }
-
Checks if the current clip has video.
Declaration
Swift
public var currentClipHasVideo: Bool { get }
-
Checks if the current clip has audio.
Declaration
Swift
public var currentClipHasAudio: Bool { get }
-
AVAsset
of the session.Declaration
Swift
public var asset: AVAsset? { get }
-
Shared pool where by which all media is allocated.
Declaration
Swift
public var pixelBufferPool: CVPixelBufferPool? { get }
-
Initialize using a specific dispatch queue.
Declaration
Swift
public convenience init(queue: DispatchQueue, queueKey: DispatchSpecificKey<()>)
Parameters
queue
Queue for a session operations
queueKey
Key for re-calling the session queue from the system
-
Initializer.
Declaration
Swift
public override init()
-
Prepares a session for recording video.
Declaration
Swift
public func setupVideo(withSettings settings: [String : Any]?, configuration: VKRecorderVideoConfiguration, formatDescription: CMFormatDescription? = nil) -> Bool
Parameters
settings
AVFoundation video settings dictionary
configuration
Video configuration for video output
formatDescription
sample buffer format description
Return Value
True when setup completes successfully
-
Prepares a session for recording audio.
Declaration
Swift
public func setupAudio(withSettings settings: [String : Any]?, configuration: VKRecorderAudioConfiguration, formatDescription: CMFormatDescription) -> Bool
Parameters
settings
AVFoundation audio settings dictionary
configuration
Audio configuration for audio output
formatDescription
sample buffer format description
Return Value
True when setup completes successfully
-
Regenerates the video id
This is necessary if you use upload while recording and you are recording a new video with the same session
Declaration
Swift
public func reinitVideo()
-
Completion handler type for appending a sample buffer
Declaration
Swift
public typealias VKRecorderSessionAppendSampleBufferCompletionHandler = (Bool) -> Void
-
Declaration
Swift
public func updateLastVideoCaptureTime(forPixelBuffer pixelBuffer: CVPixelBuffer, timestamp: TimeInterval, minFrameDuration: CMTime)
-
Declaration
Swift
public func updateLastVideoCaptureTime(forSampleBuffer sampleBuffer: CMSampleBuffer)
-
Declaration
Swift
public func updateLastAudioCaptureTime(forSampleBuffer sampleBuffer: CMSampleBuffer)
-
Append video sample buffer frames to a session for recording.
Declaration
Swift
public func appendVideo(withSampleBuffer sampleBuffer: CMSampleBuffer, customImageBuffer: CVPixelBuffer?, minFrameDuration: CMTime, completionHandler: VKRecorderSessionAppendSampleBufferCompletionHandler)
Parameters
sampleBuffer
Sample buffer input to be appended, unless an image buffer is also provided
imageBuffer
Optional image buffer input for writing a custom buffer
minFrameDuration
Current active minimum frame duration
completionHandler
Handler when a frame appending operation completes or fails
-
Append video pixel buffer frames to a session for recording.
Declaration
Swift
public func appendVideo(withPixelBuffer pixelBuffer: CVPixelBuffer, customImageBuffer: CVPixelBuffer?, timestamp: TimeInterval, minFrameDuration: CMTime, completionHandler: VKRecorderSessionAppendSampleBufferCompletionHandler)
Parameters
sampleBuffer
Sample buffer input to be appended, unless an image buffer is also provided
customImageBuffer
Optional image buffer input for writing a custom buffer
minFrameDuration
Current active minimum frame duration
completionHandler
Handler when a frame appending operation completes or fails
-
Append audio sample buffer to a session for recording.
Declaration
Swift
public func appendAudio(withSampleBuffer sampleBuffer: CMSampleBuffer, completionHandler: @escaping VKRecorderSessionAppendSampleBufferCompletionHandler)
Parameters
sampleBuffer
Sample buffer input to be appended
completionHandler
Handler when a frame appending operation completes or fails
-
Resets a session to the initial state.
Declaration
Swift
public func reset()
-
Finalize upload while recording. Called after finished recording a clip.
Declaration
Swift
public func finalizeUploadWhileRecording()
-
Completion handler type for ending a clip
Declaration
Swift
public typealias VKRecorderSessionEndClipCompletionHandler = (VKRecorderClip?, Error?) -> Void
-
Starts a clip if necessary
Declaration
Swift
public func beginClip()
-
Finalizes the recording of a clip.
Declaration
Swift
public func endClip(completionHandler: VKRecorderSessionEndClipCompletionHandler?)
Parameters
completionHandler
Handler for when a clip is finalized or finalization fails
-
Helper function that provides the location of the last recorded clip. This is helpful when merging multiple segments isn’t desired.
Declaration
Swift
public var lastClipUrl: URL? { get }
Return Value
URL path to the last recorded clip.
-
Adds a specific clip to a session.
Declaration
Swift
public func add(clip: VKRecorderClip)
Parameters
clip
Clip to be added
-
Adds a specific clip to a session at the desired index.
Declaration
Swift
public func add(clip: VKRecorderClip, at idx: Int)
Parameters
clip
Clip to be added
idx
Index at which to add the clip
-
Adds/overrides clips with given clip array
Declaration
Swift
public func setClips(clips: [VKRecorderClip])
Parameters
clips
Clips to be overridden
-
Replaces an existing clip
Declaration
Swift
public func replace(clip: VKRecorderClip, atIndex index: Int)
Parameters
clip
Clip to be added
index
Index at which to replace the clip
-
Repositions a specific clip to a desired index. The clip is going to be removed from its current and inserted into the specified index (not replaced).
Declaration
Swift
public func reposition(clip: VKRecorderClip, to indexTo: Int)
Parameters
clip
Clip to be added
idx
Index at which to add the clip to
-
Repositions a specific clip by index to a new desired index. The clip is going to be removed from its current and inserted into the specified index (not replaced).
Declaration
Swift
public func reposition(fromIndex indexFrom: Int, to indexTo: Int)
Parameters
clip
Clip to be added
idx
Index at which to add the clip to
-
Removes a specific clip from a session.
Declaration
Swift
public func remove(clip: VKRecorderClip)
Parameters
clip
Clip to be removed
-
Removes a clip from a session at the desired index.
Declaration
Swift
public func remove(clipAt idx: Int, removeFile: Bool)
Parameters
idx
Index of the clip to remove
removeFile
True to remove the associated file with the clip
-
Removes and destroys all clips for a session.
Declaration
Swift
public func removeAllClips(removeFiles: Bool = true)
Parameters
removeFiles
When true, associated files are also removed.
-
Removes the last recorded clip for a session, “Undo”.
Declaration
Swift
public func removeLastClip()
-
Completion handler type for merging clips, optionals indicate success or failure when nil
Declaration
Swift
public typealias VKRecorderSessionMergeClipsCompletionHandler = (URL?, Error?) -> Void
-
Merges all existing recorded clips in the session and exports to a file.
Declaration
Swift
public func mergeClips(usingPreset preset: String, completionHandler: @escaping VKRecorderSessionMergeClipsCompletionHandler)
Parameters
preset
AVAssetExportSession preset name for export
completionHandler
Handler for when the merging process completes