From a832f27a5a930e960be6b8e63c498db8de4d135f Mon Sep 17 00:00:00 2001 From: Syed Haris Ali Date: Tue, 30 Jun 2015 12:36:24 -0700 Subject: [PATCH] added nice description method to EZAudioFile and updated play file examples to use notifications --- EZAudio/EZAudioFile.m | 23 +++++++++ .../PlayFileViewController.m | 46 +++++++++++++++++ .../PlayFileViewController.m | 49 +++++++++++++++++++ 3 files changed, 118 insertions(+) diff --git a/EZAudio/EZAudioFile.m b/EZAudio/EZAudioFile.m index a76618b..b6cb0df 100644 --- a/EZAudio/EZAudioFile.m +++ b/EZAudio/EZAudioFile.m @@ -676,6 +676,29 @@ typedef struct [self seekToFrame:frame]; } +//------------------------------------------------------------------------------ +#pragma mark - Description +//------------------------------------------------------------------------------ + +- (NSString *)description +{ + return [NSString stringWithFormat:@"%@ {\n" + " url: %@,\n" + " duration: %f,\n" + " totalFrames: %lld,\n" + " metadata: %@,\n" + " fileFormat: { %@ },\n" + " clientFormat: { %@ } \n" + "}", + [super description], + [self url], + [self duration], + [self totalFrames], + [self metadata], + [EZAudioUtilities stringForAudioStreamBasicDescription:[self fileFormat]], + [EZAudioUtilities stringForAudioStreamBasicDescription:[self clientFormat]]]; +} + //------------------------------------------------------------------------------ @end diff --git a/EZAudioExamples/OSX/EZAudioPlayFileExample/EZAudioPlayFileExample/PlayFileViewController.m b/EZAudioExamples/OSX/EZAudioPlayFileExample/EZAudioPlayFileExample/PlayFileViewController.m index edaca62..22a3eff 100644 --- a/EZAudioExamples/OSX/EZAudioPlayFileExample/EZAudioPlayFileExample/PlayFileViewController.m +++ b/EZAudioExamples/OSX/EZAudioPlayFileExample/EZAudioPlayFileExample/PlayFileViewController.m @@ -71,12 +71,58 @@ self.rollingHistoryLengthSlider.intValue = [self.audioPlot rollingHistoryLength]; self.rollingHistoryLengthLabel.intValue = [self.audioPlot rollingHistoryLength]; + [self setupNotifications]; + // // Try opening the sample file // [self openFileWithFilePathURL:[NSURL fileURLWithPath:kAudioFileDefault]]; } +//------------------------------------------------------------------------------ +#pragma mark - Notifications +//------------------------------------------------------------------------------ + +- (void)setupNotifications +{ + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(audioPlayerDidChangeAudioFile:) + name:EZAudioPlayerDidChangeAudioFileNotification + object:self.player]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(audioPlayerDidChangeOutputDevice:) + name:EZAudioPlayerDidChangeOutputDeviceNotification + object:self.player]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(audioPlayerDidChangePlayState:) + name:EZAudioPlayerDidChangePlayStateNotification + object:self.player]; +} + +//------------------------------------------------------------------------------ + +- (void)audioPlayerDidChangeAudioFile:(NSNotification *)notification +{ + EZAudioPlayer *player = [notification object]; + NSLog(@"Player changed audio file: %@", [player audioFile]); +} + +//------------------------------------------------------------------------------ + +- (void)audioPlayerDidChangeOutputDevice:(NSNotification *)notification +{ + EZAudioPlayer *player = [notification object]; + NSLog(@"Player changed output device: %@", [player device]); +} + +//------------------------------------------------------------------------------ + +- (void)audioPlayerDidChangePlayState:(NSNotification *)notification +{ + EZAudioPlayer *player = [notification object]; + NSLog(@"Player change play state, isPlaying: %i", [player isPlaying]); +} + //------------------------------------------------------------------------------ #pragma mark - Actions //------------------------------------------------------------------------------ diff --git a/EZAudioExamples/iOS/EZAudioPlayFileExample/EZAudioPlayFileExample/PlayFileViewController.m b/EZAudioExamples/iOS/EZAudioPlayFileExample/EZAudioPlayFileExample/PlayFileViewController.m index 48bba44..aa43454 100644 --- a/EZAudioExamples/iOS/EZAudioPlayFileExample/EZAudioPlayFileExample/PlayFileViewController.m +++ b/EZAudioExamples/iOS/EZAudioPlayFileExample/EZAudioPlayFileExample/PlayFileViewController.m @@ -42,12 +42,61 @@ // self.rollingHistorySlider.value = (float)[self.audioPlot rollingHistoryLength]; + // + // Listen for EZAudioPlayer notifications + // + [self setupNotifications]; + /* Try opening the sample file */ [self openFileWithFilePathURL:[NSURL fileURLWithPath:kAudioFileDefault]]; } +//------------------------------------------------------------------------------ +#pragma mark - Notifications +//------------------------------------------------------------------------------ + +- (void)setupNotifications +{ + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(audioPlayerDidChangeAudioFile:) + name:EZAudioPlayerDidChangeAudioFileNotification + object:self.player]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(audioPlayerDidChangeOutputDevice:) + name:EZAudioPlayerDidChangeOutputDeviceNotification + object:self.player]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(audioPlayerDidChangePlayState:) + name:EZAudioPlayerDidChangePlayStateNotification + object:self.player]; +} + +//------------------------------------------------------------------------------ + +- (void)audioPlayerDidChangeAudioFile:(NSNotification *)notification +{ + EZAudioPlayer *player = [notification object]; + NSLog(@"Player changed audio file: %@", [player audioFile]); +} + +//------------------------------------------------------------------------------ + +- (void)audioPlayerDidChangeOutputDevice:(NSNotification *)notification +{ + EZAudioPlayer *player = [notification object]; + NSLog(@"Player changed output device: %@", [player device]); +} + +//------------------------------------------------------------------------------ + +- (void)audioPlayerDidChangePlayState:(NSNotification *)notification +{ + EZAudioPlayer *player = [notification object]; + NSLog(@"Player change play state, isPlaying: %i", [player isPlaying]); +} + //------------------------------------------------------------------------------ #pragma mark - Actions //------------------------------------------------------------------------------