AKAudioPlayer

open class AKAudioPlayer: AKNode, AKToggleable

Not so simple audio playback class

  • Will be triggered when AKAudioPlayer has finished to play. (will not as long as loop is on)

    Declaration

    Swift

    open var completionHandler: AKCallback?
  • Boolean indicating whether or not to loop the playback

    Declaration

    Swift

    open var looping: Bool = false
  • return the current played AKAudioFile

    Declaration

    Swift

    open var audioFile: AKAudioFile
  • Undocumented

    Declaration

    Swift

    open class AKAudioPlayer: AKNode, AKToggleable
  • Total duration of one loop through of the file

    Declaration

    Swift

    open var duration: Double
  • Output Volume (Default 1)

    Declaration

    Swift

    open var volume: Double = 1.0
  • Whether or not the audio player is currently started

    Declaration

    Swift

    open var isStarted: Bool
  • Current playback time (in seconds)

    Declaration

    Swift

    open var currentTime: Double
  • Time within the audio file at the current time

    Declaration

    Swift

    open var playhead: Double
  • pan

    Pan (Default Center = 0)

    Declaration

    Swift

    open var pan: Double = 0.0
  • sets the start time, If it is playing, player will restart playing from the start time each time end time is set

    Declaration

    Swift

    open var startTime: Double
  • sets the end time, If it is playing, player will restart playing from the start time each time end time is set

    Declaration

    Swift

    open var endTime: Double
  • Sets the time in the future when playback will commence. For immediately playback, leave it 0.

    Declaration

    Swift

    open var scheduledTime: Double = 0
  • Initialize the audio player

    Notice that completionCallBack will be triggered from a background thread. Any UI update should be made using:

    Dispatch.main.async {
       // UI updates...
    }
    

  • Parameters:

    • file: the AKAudioFile to play
    • looping : will loop play if set to true, or stop when play ends, so it can trig the completionHandler callback. Default is false (non looping)
    • completionHandler : AKCallback that will be triggered when the player end playing (useful for refreshing UI so we’re not playing anymore, we stopped playing…
  • Returns

    an AKAudioPlayer if init succeeds, or nil if init fails. If fails, errors may be catched as it is a throwing init.

    Declaration

    Swift

    public init(file: AKAudioFile, looping:Bool = false, completionHandler: AKCallback? = nil) throws

    Parameters

    file

    the AKAudioFile to play

    looping

    will loop play if set to true, or stop when play ends, so it can trig the completionHandler callback. Default is false (non looping)

    completionHandler

    AKCallback that will be triggered when the player end playing (useful for refreshing UI so we’re not playing anymore, we stopped playing…

    Return Value

    an AKAudioPlayer if init succeeds, or nil if init fails. If fails, errors may be catched as it is a throwing init.

  • Start playback

    Declaration

    Swift

    open func start()
  • Stop playback

    Declaration

    Swift

    open func stop()
  • Pause playback

    Declaration

    Swift

    open func pause()
  • resets in and out times for playing

    Declaration

    Swift

    open func reloadFile() throws
  • Replace player’s file with a new AKAudioFile file

    Declaration

    Swift

    open func replace(file: AKAudioFile) throws
  • Play the file back from a certain time, to an end time (if set). You can optionally set a scheduled time to play (in seconds).

    • Parameters:
      • time: Time into the file at which to start playing back
      • endTime: Time into the file at which to playing back will stop / Loop
      • scheduledTime: Time in the future to start playback. This is useful for scheduling a group of sounds to start concurrently, or to simply schedule the start time.

    Declaration

    Swift

    open func play(from time: Double, to endTime: Double = 0, when scheduledTime: Double = 0)

    Parameters

    time

    Time into the file at which to start playing back

    endTime

    Time into the file at which to playing back will stop / Loop

    scheduledTime

    Time in the future to start playback. This is useful for scheduling a group of sounds to start concurrently, or to simply schedule the start time.