這篇文章與上一篇極其類似,要注意別看錯。session
.hui
#import <UIKit/UIKit.h> #import <AVFoundation/AVFoundation.h> @interface PlayViewController: UIViewController @property (strong, nonatomic) AVPlayer *player; @end
.matom
#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 = [[AVPlayer alloc] initWithContentsOfURL:audioUrl error:&playerError]; if (_player === NULL) { NSLog(@"fail to play audio :("); return; } [_player setVolume:1]; [_player play]; } - (void) didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } @end
http://download.csdn.net/detail/prevention/6817053.net
-code
轉載請註明來自:http://blog.csdn.net/preventionblog