AudioPlayerDelegate
@protocol AudioPlayerDelegate <NSObject>
The AudioPlayerDelegate provides event callbacks for the AudioPlayer. AudioPlayerDelegate provides a small set of delegate methods in favor of notifications to allow multiple receivers of the AudioPlayer event callbacks since only one player is typically used in an application. Specifically, these methods are provided for high frequency callbacks that wrap the AudioPlayer’s internal EZAudioFile and EZOutput instances. - warning: These callbacks don’t necessarily occur on the main thread so make sure you wrap any UI code in a GCD block like: dispatch_async(dispatch_get_main_queue(), ^{ // Update UI });
-
Triggered by the AudioPlayer’s internal EZAudioFile’s EZAudioFileDelegate callback and notifies the delegate of the read audio data as a float array instead of a buffer list. Common use case of this would be to visualize the float data using an audio plot or audio data dependent OpenGL sketch. - parameter: audioPlayer The instance of the AudioPlayer that triggered the event - parameter: buffer A float array of float arrays holding the audio data. buffer[0] would be the left channel’s float array while buffer[1] would be the right channel’s float array in a stereo file. - parameter: bufferSize The length of the buffers float arrays - parameter: numberOfChannels The number of channels. 2 for stereo, 1 for mono. - parameter: audioFile The instance of the EZAudioFile that the event was triggered from
Declaration
Objective-C
- (void)audioPlayer:(AudioPlayer *)audioPlayer playedAudio:(float **)buffer withBufferSize:(UInt32)bufferSize withNumberOfChannels:(UInt32)numberOfChannels inAudioFile:(EZAudioFile *)audioFile;
Swift
optional func audioPlayer(_ audioPlayer: AudioPlayer!, playedAudio buffer: UnsafeMutablePointer
Parameters
audioPlayer
The instance of the AudioPlayer that triggered the event
buffer
A float array of float arrays holding the audio data. buffer[0] would be the left channel’s float array while buffer[1] would be the right channel’s float array in a stereo file.
bufferSize
The length of the buffers float arrays
numberOfChannels
The number of channels. 2 for stereo, 1 for mono.
audioFile
The instance of the EZAudioFile that the event was triggered from
-
Triggered by AudioPlayer’s internal EZAudioFile’s EZAudioFileDelegate callback and notifies the delegate of the current playback position. The framePosition provides the current frame position and can be calculated against the AudioPlayer’s total frames using the
totalFrames
function from the AudioPlayer. - parameter: audioPlayer The instance of the AudioPlayer that triggered the event - parameter: framePosition The new frame index as a 64-bit signed integer - parameter: audioFile The instance of the EZAudioFile that the event was triggered fromDeclaration
Objective-C
- (void)audioPlayer:(AudioPlayer *)audioPlayer updatedPosition:(SInt64)framePosition inAudioFile:(EZAudioFile *)audioFile;
Swift
optional func audioPlayer(_ audioPlayer: AudioPlayer!, updatedPosition framePosition: Int64, in audioFile: EZAudioFile!)
Parameters
audioPlayer
The instance of the AudioPlayer that triggered the event
framePosition
The new frame index as a 64-bit signed integer
audioFile
The instance of the EZAudioFile that the event was triggered from
-
Triggered by AudioPlayer’s internal EZAudioFile’s EZAudioFileDelegate callback and notifies the delegate that the end of the file has been reached. - parameter: audioPlayer The instance of the AudioPlayer that triggered the event - parameter: audioFile The instance of the EZAudioFile that the event was triggered from
Declaration
Objective-C
- (void)audioPlayer:(AudioPlayer *)audioPlayer reachedEndOfAudioFile:(EZAudioFile *)audioFile;
Swift
optional func audioPlayer(_ audioPlayer: AudioPlayer!, reachedEndOf audioFile: EZAudioFile!)
Parameters
audioPlayer
The instance of the AudioPlayer that triggered the event
audioFile
The instance of the EZAudioFile that the event was triggered from