NextLevelSession
public class NextLevelSession
NextLevelSession, a powerful object for managing and editing a set of recorded media clips.
-
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 identifier: UUID { get }
-
Creation date for a session.
Declaration
Swift
public var date: Date { get }
-
Creates a URL for session output, otherwise nil
Declaration
Swift
public var url: URL? { get }
-
Undocumented
Declaration
Swift
public var isVideoSetup: Bool { get }
-
Checks if the session is setup for recording video
Declaration
Swift
public var isVideoReady: Bool { get }
-
Undocumented
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: [NextLevelClip] { 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 isReady: 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 init()
-
Prepares a session for recording video.
Declaration
Swift
public func setupVideo(withSettings settings: [String : Any]?, configuration: NextLevelVideoConfiguration, 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: NextLevelAudioConfiguration, 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
-
Completion handler type for appending a sample buffer
Declaration
Swift
public typealias NextLevelSessionAppendSampleBufferCompletionHandler = (Bool) -> Void
-
Append video sample buffer frames to a session for recording.
Declaration
Swift
public func appendVideo(withSampleBuffer sampleBuffer: CMSampleBuffer, customImageBuffer: CVPixelBuffer?, minFrameDuration: CMTime, completionHandler: NextLevelSessionAppendSampleBufferCompletionHandler)
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: NextLevelSessionAppendSampleBufferCompletionHandler)
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 NextLevelSessionAppendSampleBufferCompletionHandler)
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()
-
Completion handler type for ending a clip
Declaration
Swift
public typealias NextLevelSessionEndClipCompletionHandler = (NextLevelClip?, Error?) -> Void
-
Starts a clip
Declaration
Swift
public func beginClip()
-
Finalizes the recording of a clip.
Declaration
Swift
public func endClip(completionHandler: NextLevelSessionEndClipCompletionHandler?)
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: NextLevelClip)
Parameters
clip
Clip to be added
-
Adds a specific clip to a session at the desired index.
Declaration
Swift
public func add(clip: NextLevelClip, at idx: Int)
Parameters
clip
Clip to be added
idx
Index at which to add the clip
-
Removes a specific clip from a session.
Declaration
Swift
public func remove(clip: NextLevelClip)
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 NextLevelSessionMergeClipsCompletionHandler = (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 NextLevelSessionMergeClipsCompletionHandler)
Parameters
preset
AVAssetExportSession preset name for export
completionHandler
Handler for when the merging process completes