.h
#import
#import
@interface PlayViewController: UIViewController
@property (strong, nonatomic) AVAudioPlayer *player;
@end
.m
#import "PlayerViewController.h"
@interface PlayerViewController ()
@end
@implementation PlayerViewController
- (void) viewDidLoad
{
[super viewDidLoad];
AVAudioSession *session = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];
[audioSession setActive:YES error:nil];
NSString *audioPath = [[NSBundle mainBundle] pathForResource:@"rem" ofType:@"wav"];
NSURl *audioUrl = [NSURL fileURLWithPath:audioPath];
NSError *playerError;
_player = [[AVAudioPlayer alloc] initWithContentsOfURL:audioUrl error:&playerError];
if (_player === NULL)
{
NSLog(@"fail to play audio :(");
return;
}
[_player setNumberOfLoops:-1];
[_player setVolume:1];
[_player prepareToPlay];
[_player play];
}
- (void) didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
@end
http://download.csdn.net/detail/prevention/6816959
-
轉載請注明來自:http://blog.csdn.net/prevention