AKAudioPlayer
open class AKAudioPlayer : AKNode, AKToggleable
Not so simple audio playback class
-
Declaration
Swift
@objc open dynamic var audioFileBuffer: AVAudioPCMBuffer? { get set }
-
Will be triggered when AKAudioPlayer has finished to play. (will not as long as loop is on)
Declaration
Swift
@objc open dynamic var completionHandler: AKCallback?
-
Boolean indicating whether or not to loop the playback (Default false)
Declaration
Swift
@objc open dynamic var looping: Bool { get set }
-
Boolean indicating to play the buffer in reverse
Declaration
Swift
@objc open dynamic var reversed: Bool { get set }
-
Fade in duration
Declaration
Swift
@objc open dynamic var fadeInTime: Double { get set }
-
Fade out duration
Declaration
Swift
@objc open dynamic var fadeOutTime: Double { get set }
-
The current played AKAudioFile
Declaration
Swift
@objc open dynamic var audioFile: AKAudioFile { get }
-
Path to the currently loaded AKAudioFile
Declaration
Swift
@objc open dynamic var path: String { get }
-
Total duration of one loop through of the file
Declaration
Swift
@objc open dynamic var duration: Double { get }
-
Output Volume (Default 1)
Declaration
Swift
@objc open dynamic var volume: Double { get set }
-
Whether or not the audio player is currently started
Declaration
Swift
@objc open dynamic var isStarted: Bool { get }
-
Current playback time (in seconds)
Declaration
Swift
@objc open dynamic var currentTime: Double { get }
-
Time within the audio file at the current time
Declaration
Swift
@objc open dynamic var playhead: Double { get }
-
Pan (Default Center = 0)
Declaration
Swift
@objc open dynamic var pan: Double { get set }
-
Seconds into the audio file to start playback at
Declaration
Swift
@objc open dynamic var startTime: Double { get set }
-
Seconds into the audio file to stop playback
Declaration
Swift
@objc open dynamic var endTime: Double { get set }
-
Sets the time in the future when playback will commence. Recommend using play(from:to:avTime) instead. this will be deprecated
Declaration
Swift
@objc open dynamic var scheduledTime: Double { get set }
-
Sheduled time
Declaration
Swift
@objc open dynamic var scheduledAVTime: AVAudioTime?
-
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... }
Declaration
Swift
@objc public init(file: AKAudioFile, looping: Bool = false, lazyBuffering: 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 caught.
-
Start playback
Declaration
Swift
@objc open func start()
-
Declaration
Swift
open func play(at when: AVAudioTime?)
-
Stop playback
Declaration
Swift
@objc open func stop()
-
Pause playback
Declaration
Swift
open func pause()
-
Restart playback from current position
Declaration
Swift
open func resume()
-
resets in and out times for playing
Declaration
Swift
open func reloadFile() throws
-
Replace player’s file with a new AKAudioFile file
Declaration
Swift
@objc open func replace(file: AKAudioFile) throws
-
Default play that will use the previously set startTime and endTime properties or the full file if both are 0
Declaration
Swift
open func play()
-
Play from startTime to endTime
Declaration
Swift
@objc open func play(from startTime: Double)
-
Play from startTime to endTime
Declaration
Swift
@objc open func play(from startTime: Double, to endTime: Double)
-
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).
Declaration
Swift
open func play(from startTime: Double, to endTime: Double, when scheduledTime: Double)
Parameters
startTime
Time into the file at which to start playing back
endTime
Time into the file at which to playing back will stop / Loop
scheduledTime
use this when scheduled playback doesn’t need to be in sync with other players otherwise use the avTime signature.
-
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).
Declaration
Swift
open func play(from startTime: Double, to endTime: Double, avTime: AVAudioTime?)
Parameters
startTime
Time into the file at which to start playing back
endTime
Time into the file at which to playing back will stop / Loop
avTime
an AVAudioTime object specifying when to schedule the playback. You can create this using the helper function AKAudioPlayer.secondToAVAudioTime(hostTime:time). hostTime is a call to mach_absolute_time(). When you have a group of players which you want to sync together it’s important that this value be the same for all of them as a reference point.
-
Declaration
Swift
open func schedule(from startTime: Double, to endTime: Double, avTime: AVAudioTime?)
-
return the peak time in the currently loaded buffer
Declaration
Swift
open func getPeakTime() -> Double
-
Convert to AVAudioTime
Declaration
Swift
open class func secondsToAVAudioTime(hostTime: UInt64, time: Double) -> AVAudioTime
-
Stop playback after next loop completes
Declaration
Swift
@objc open func stopAtNextLoopEnd()
-
Declaration
Swift
open override func detach()