From 115dc2b8a0c54f4051b59d9ddbcc313de54bc8f5 Mon Sep 17 00:00:00 2001 From: Syed Haris Ali Date: Tue, 30 Jun 2015 13:03:34 -0700 Subject: [PATCH] updated play file example for notifications and added loop checkbox for OSX, fixed audio session not being set on iOS FFT example --- .../PlayFileViewController.h | 10 +++++++ .../PlayFileViewController.m | 26 +++++++++++++++++++ .../PlayFileViewController.xib | 14 ++++++++++ .../EZAudioFFTExample/FFTViewController.m | 19 +++++++++++++- .../PlayFileViewController.m | 3 +-- 5 files changed, 69 insertions(+), 3 deletions(-) diff --git a/EZAudioExamples/OSX/EZAudioPlayFileExample/EZAudioPlayFileExample/PlayFileViewController.h b/EZAudioExamples/OSX/EZAudioPlayFileExample/EZAudioPlayFileExample/PlayFileViewController.h index b4df9c5..1947931 100644 --- a/EZAudioExamples/OSX/EZAudioPlayFileExample/EZAudioPlayFileExample/PlayFileViewController.h +++ b/EZAudioExamples/OSX/EZAudioPlayFileExample/EZAudioPlayFileExample/PlayFileViewController.h @@ -61,6 +61,11 @@ */ @property (nonatomic, weak) IBOutlet NSTextField *filePathLabel; +/** + A checkbox button to that allows you to specify if the audio player should loop. + */ +@property (nonatomic, weak) IBOutlet NSButton *loopCheckboxButton; + /** A label to display the audio file's current position. */ @@ -112,6 +117,11 @@ */ - (IBAction)changeRollingHistoryLength:(id)sender; +/** + Switches the loop state on the audio player regarding whether the current playing audio file should loop back to the beginning when it finishes. + */ +- (IBAction)changeShouldLoop:(id)sender; + /** Changes the volume of the audio coming out of the EZOutput. */ diff --git a/EZAudioExamples/OSX/EZAudioPlayFileExample/EZAudioPlayFileExample/PlayFileViewController.m b/EZAudioExamples/OSX/EZAudioPlayFileExample/EZAudioPlayFileExample/PlayFileViewController.m index 22a3eff..f9b1ed3 100644 --- a/EZAudioExamples/OSX/EZAudioPlayFileExample/EZAudioPlayFileExample/PlayFileViewController.m +++ b/EZAudioExamples/OSX/EZAudioPlayFileExample/EZAudioPlayFileExample/PlayFileViewController.m @@ -70,7 +70,11 @@ self.volumeLabel.floatValue = [self.player volume]; self.rollingHistoryLengthSlider.intValue = [self.audioPlot rollingHistoryLength]; self.rollingHistoryLengthLabel.intValue = [self.audioPlot rollingHistoryLength]; + self.loopCheckboxButton.state = [self.player shouldLoop]; + // + // Listen for state changes to the EZAudioPlayer + // [self setupNotifications]; // @@ -97,6 +101,12 @@ selector:@selector(audioPlayerDidChangePlayState:) name:EZAudioPlayerDidChangePlayStateNotification object:self.player]; + + // This notification will only trigger if the player's shouldLoop property is set to NO + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(audioPlayerDidReachEndOfFile:) + name:EZAudioPlayerDidReachEndOfFileNotification + object:self.player]; } //------------------------------------------------------------------------------ @@ -123,6 +133,14 @@ NSLog(@"Player change play state, isPlaying: %i", [player isPlaying]); } +//------------------------------------------------------------------------------ + +- (void)audioPlayerDidReachEndOfFile:(NSNotification *)notification +{ + NSLog(@"Player did reach end of file!"); + [self.playButton setState:NSOffState]; +} + //------------------------------------------------------------------------------ #pragma mark - Actions //------------------------------------------------------------------------------ @@ -153,6 +171,14 @@ //------------------------------------------------------------------------------ +- (void)changeShouldLoop:(id)sender +{ + NSInteger state = [(NSButton *)sender state]; + [self.player setShouldLoop:state]; +} + +//------------------------------------------------------------------------------ + - (void)changeVolume:(id)sender { float value = [(NSSlider *)sender floatValue]; diff --git a/EZAudioExamples/OSX/EZAudioPlayFileExample/EZAudioPlayFileExample/PlayFileViewController.xib b/EZAudioExamples/OSX/EZAudioPlayFileExample/EZAudioPlayFileExample/PlayFileViewController.xib index f943505..1a9facb 100644 --- a/EZAudioExamples/OSX/EZAudioPlayFileExample/EZAudioPlayFileExample/PlayFileViewController.xib +++ b/EZAudioExamples/OSX/EZAudioPlayFileExample/EZAudioPlayFileExample/PlayFileViewController.xib @@ -8,7 +8,9 @@ + + @@ -192,6 +194,16 @@ + @@ -199,6 +211,7 @@ + @@ -209,6 +222,7 @@ + diff --git a/EZAudioExamples/iOS/EZAudioFFTExample/EZAudioFFTExample/FFTViewController.m b/EZAudioExamples/iOS/EZAudioFFTExample/EZAudioFFTExample/FFTViewController.m index 2261db2..de628ba 100644 --- a/EZAudioExamples/iOS/EZAudioFFTExample/EZAudioFFTExample/FFTViewController.m +++ b/EZAudioExamples/iOS/EZAudioFFTExample/EZAudioFFTExample/FFTViewController.m @@ -49,6 +49,23 @@ { [super viewDidLoad]; + // + // Setup the AVAudioSession. EZMicrophone will not work properly on iOS + // if you don't do this! + // + AVAudioSession *session = [AVAudioSession sharedInstance]; + NSError *error; + [session setCategory:AVAudioSessionCategoryPlayAndRecord error:&error]; + if (error) + { + NSLog(@"Error setting up audio session category: %@", error.localizedDescription); + } + [session setActive:YES error:&error]; + if (error) + { + NSLog(@"Error setting up audio session active: %@", error.localizedDescription); + } + /* Customizing the audio plot's look */ @@ -70,7 +87,7 @@ Start the microphone */ self.microphone = [EZMicrophone microphoneWithDelegate:self - startsImmediately:YES]; + startsImmediately:YES]; } diff --git a/EZAudioExamples/iOS/EZAudioPlayFileExample/EZAudioPlayFileExample/PlayFileViewController.m b/EZAudioExamples/iOS/EZAudioPlayFileExample/EZAudioPlayFileExample/PlayFileViewController.m index aa43454..e6187e1 100644 --- a/EZAudioExamples/iOS/EZAudioPlayFileExample/EZAudioPlayFileExample/PlayFileViewController.m +++ b/EZAudioExamples/iOS/EZAudioPlayFileExample/EZAudioPlayFileExample/PlayFileViewController.m @@ -33,8 +33,7 @@ // // Create the audio player // - self.player = [EZAudioPlayer audioPlayer]; - self.player.delegate = self; + self.player = [EZAudioPlayer audioPlayerWithDelegate:self]; self.player.shouldLoop = YES; //