NextLevelSession
public class NextLevelSession: NSObject
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 = .mp4
-
Output file extension for a session, see AVMediaFormat.h for supported extensions.
Declaration
Swift
public var fileExtension: String = "mp4"
-
Unique identifier for a session.
Declaration
Swift
public var identifier: String
-
Creation date for a session.
Declaration
Swift
public var date: Date
-
Creates a URL for session output, otherwise nil
Declaration
Swift
public var url: URL?
-
Checks if the session is setup for recording video
Declaration
Swift
public var isVideoReady: Bool
-
Checks if the session is setup for recording audio
Declaration
Swift
public var isAudioReady: Bool
-
Recorded clips for the session.
Declaration
Swift
public var clips: [NextLevelClip]
-
Duration of a session, the sum of all recorded clips.
Declaration
Swift
public var duration: CMTime
-
Checks if the session’s asset writer is ready for data.
Declaration
Swift
public var isReady: Bool
-
True if the current clip recording has been started.
Declaration
Swift
public var clipStarted: Bool
-
Duration of the current clip.
Declaration
Swift
public var currentClipDuration: CMTime
-
Checks if the current clip has video.
Declaration
Swift
public var currentClipHasVideo: Bool
-
Checks if the current clip has audio.
Declaration
Swift
public var currentClipHasAudio: Bool
-
AVAsset
of the session.Declaration
Swift
public var asset: AVAsset?
-
Shared pool where by which all media is allocated.
Declaration
Swift
public var pixelBufferPool: CVPixelBufferPool?
-
Prepares a session for recording video.
- Parameters:
- settings: AVFoundation video settings dictionary
- configuration: Video configuration for video output
- formatDescription: sample buffer format description
Returns
True when setup completes successfullyDeclaration
Swift
public func setupVideo(withSettings settings: [String : Any]?, configuration: NextLevelVideoConfiguration, formatDescription: CMFormatDescription? = nil) -> Bool
- Parameters:
-
Prepares a session for recording audio.
- Parameters:
- settings: AVFoundation audio settings dictionary
- configuration: Audio configuration for audio output
- formatDescription: sample buffer format description
Returns
True when setup completes successfullyDeclaration
Swift
public func setupAudio(withSettings settings: [String : Any]?, configuration: NextLevelAudioConfiguration, formatDescription: CMFormatDescription) -> Bool
- Parameters:
-
Append video sample buffer frames to a session for recording.
- 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
Declaration
Swift
public func appendVideo(withSampleBuffer sampleBuffer: CMSampleBuffer, customImageBuffer: CVPixelBuffer?, minFrameDuration: CMTime, completionHandler: NextLevelSessionAppendSampleBufferCompletionHandler)
- Parameters:
-
Completion handler type for appending a sample buffer
Declaration
Swift
public typealias NextLevelSessionAppendSampleBufferCompletionHandler = (_: Bool) -> Void
-
Completion handler type for ending a clip
Declaration
Swift
public typealias NextLevelSessionEndClipCompletionHandler = (_: NextLevelClip?, _: Error?) -> Void
-
Append video pixel buffer frames to a session for recording.
- 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
Declaration
Swift
public func appendVideo(withPixelBuffer pixelBuffer: CVPixelBuffer, customImageBuffer: CVPixelBuffer?, timestamp: TimeInterval, minFrameDuration: CMTime, completionHandler: NextLevelSessionAppendSampleBufferCompletionHandler)
- Parameters:
-
Append audio sample buffer to a session for recording.
- Parameters:
- sampleBuffer: Sample buffer input to be appended
- completionHandler: Handler when a frame appending operation completes or fails
Declaration
Swift
public func appendAudio(withSampleBuffer sampleBuffer: CMSampleBuffer, completionHandler: @escaping NextLevelSessionAppendSampleBufferCompletionHandler)
- Parameters:
-
Resets a session to the initial state.
Declaration
Swift
public func reset()
-
Starts a clip
Declaration
Swift
public func beginClip()
-
Finalizes the recording of a clip.
Parameter
Parameter completionHandler: Handler for when a clip is finalized or finalization failsDeclaration
Swift
public func endClip(completionHandler: NextLevelSessionEndClipCompletionHandler?)
-
Helper function that provides the location of the last recorded clip. This is helpful when merging multiple segments isn’t desired.
Returns
URL path to the last recorded clip.Declaration
Swift
public var lastClipUrl: URL?
-
Completion handler type for merging clips, optionals indicate success or failure when nil
Declaration
Swift
public typealias NextLevelSessionMergeClipsCompletionHandler = (_: URL?, _: Error?) -> Void
-
Adds a specific clip to a session.
Parameter
Parameter clip: Clip to be addedDeclaration
Swift
public func add(clip: NextLevelClip)
-
Adds a specific clip to a session at the desired index.
- Parameters:
- clip: Clip to be added
- idx: Index at which to add the clip
Declaration
Swift
public func add(clip: NextLevelClip, at idx: Int)
- Parameters:
-
Removes a specific clip from a session.
Parameter
Parameter clip: Clip to be removedDeclaration
Swift
public func remove(clip: NextLevelClip)
-
Removes a clip from a session at the desired index.
- Parameters:
- idx: Index of the clip to remove
- removeFile: True to remove the associated file with the clip
Declaration
Swift
public func remove(clipAt idx: Int, removeFile: Bool)
- Parameters:
-
Removes and destroys all clips for a session.
Parameter
Parameter removeFiles: When true, associated files are also removed.Declaration
Swift
public func removeAllClips(removeFiles: Bool = true)
-
Removes the last recorded clip for a session,
Undo
.Declaration
Swift
public func removeLastClip()
-
Merges all existing recorded clips in the session and exports to a file.
- Parameters:
- preset: AVAssetExportSession preset name for export
- completionHandler: Handler for when the merging process completes
Declaration
Swift
public func mergeClips(usingPreset preset: String, completionHandler: @escaping NextLevelSessionMergeClipsCompletionHandler)
- Parameters: