.hsession
#import <UIKit/UIKit.h> #import <AVFoundation/AVFoundation.h> @interface PlayViewController: UIViewController @property (strong, nonatomic) AVAudioPlayer *player; @end
.moop
#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/6816959ui
-atom
轉載請註明來自:http://blog.csdn.net/prevention.net