iOS学习笔记31-音频

#import <AVFoundation/AVFoundation.h>

 

@interface ViewController ()

@property(nonatomic,strong)AVAudioPlayer *player;

@end

 

@implementation ViewController

 

-(AVAudioPlayer *)player

{

    if (!_player) {

        NSURL *url = [[NSBundle mainBundle]URLForResource:@"爱火花.mp3" withExtension:nil];

        

        _player = [[AVAudioPlayer alloc]initWithContentsOfURL:url error:nil];

        [self.player prepareToPlay];

        

    }

    return _player;

}

 

 

- (IBAction)play {

    [self.player play];

    

}

- (IBAction)pause:(id)sender {

    [self.player pause];

}

- (IBAction)stop {

    [self.player stop];

    

}

 

posted @ 2016-02-29 20:11  small-elephant_A-Do  阅读(120)  评论(0编辑  收藏  举报