Created
December 24, 2015 07:05
-
-
Save ykws/b0f2fc9954f613f57b1e to your computer and use it in GitHub Desktop.
Play background music on iOS
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
#import "MainViewController.h" | |
#import <AVFoundation/AVFoundation.h> | |
@interface MainViewController () | |
@property (strong, nonatomic) AVAudioPlayer *player; | |
@end | |
@implementation MainViewController | |
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"bgm" ofType:@"mp3"]] error:nil]; | |
self.player.numberOfLoops = -1; | |
[self.player prepareToPlay]; | |
[self.player play]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment