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
  • url

    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 successfully

    Declaration

    Swift

    public func setupVideo(withSettings settings: [String : Any]?, configuration: NextLevelVideoConfiguration, formatDescription: CMFormatDescription? = nil) -> Bool
  • 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 successfully

    Declaration

    Swift

    public func setupAudio(withSettings settings: [String : Any]?, configuration: NextLevelAudioConfiguration, formatDescription: CMFormatDescription) -> Bool
  • 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 added

    Declaration

    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)
  • Removes a specific clip from a session.

    Parameter

    Parameter clip: Clip to be removed

    Declaration

    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)
  • 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)