Created
July 13, 2010 22:24
-
-
Save jtrim/474650 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// AudioPauseLoopAppDelegate.m | |
// AudioPauseLoop | |
// | |
// Created by Jesse Trimble on 7/13/10. | |
// Copyright n/a 2010. All rights reserved. | |
// | |
#import <UIKit/UIKit.h> | |
#import "AudioPauseLoopAppDelegate.h" | |
#import <AVFoundation/AVFoundation.h> | |
// start interface | |
@interface AudioPauseLoopAppDelegate : NSObject <UIApplicationDelegate ,AVAudioPlayerDelegate> | |
{ | |
UIWindow *window; | |
int currentAudioIndex; | |
NSArray *audioFileNames; | |
} | |
@property (nonatomic, retain) IBOutlet UIWindow *window; | |
@end | |
// end interface | |
// begin implementation | |
@implementation AudioPauseLoopAppDelegate | |
@synthesize window; | |
#pragma mark - | |
#pragma mark Application lifecycle | |
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions | |
{ | |
currentAudioIndex = 0; | |
audioFileNames = [[NSArray alloc] initWithObjects:@"sound1.mp3", @"sound2.mp3", @"sound3.mp3"]; | |
[self playSound:[audioFileNames objectAtIndex:0]]; | |
[window makeKeyAndVisible]; | |
return YES; | |
} | |
- (void)playSound:(NSString *)fileName | |
{ | |
NSString *audioPath = [[NSBundle mainBundle] pathForResource:[[fileName componentsSeparatedByString:@"."] objectAtIndex:0] ofType:[[fileName componentsSeparatedByString:@"."] objectAtIndex:1]]; | |
NSData *audioData = [[NSData alloc] initWithContentsOfFile:audioPath]; | |
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithData:audioData error:NULL]; | |
[player setDelegate:self]; | |
[player prepareToPlay]; | |
[player play]; | |
} | |
-(void) audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag | |
{ | |
if (currentAudioIndex >= [audioFileNames count]) | |
currentAudioIndex = 0; | |
[self performSelector:@selector(playSound:) withObject:[audioFileNames objectAtIndex:currentAudioIndex] afterDelay:.5f]; | |
[player release]; | |
} | |
- (void)dealloc | |
{ | |
[window release]; | |
[super dealloc]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment