NSTimer和AVAudioPlayer的简单使用

:NSTimer的使用方法

[NSTimerscheduledTimerWithTimeInterval:0.2 target:selfselector:@selector(changeColor)

                                   userInfo:nil repeats:YES];

 
//让NSTimer消失的方法
[_timer  invalidate];
 
:AVAudioPlayer的简单使用

     //创建音乐文件路径

    NSString * musicFilePath = [[NSBundlemainBundle]pathForResource:@"jnstyle"ofType:@"mp3"];

    //根据路径创建url路径

    NSURL * musicURL = [[NSURL alloc]initFileURLWithPath:musicFilePath];

    //创建播放器

    AVAudioPlayer *thePlayer = [[AVAudioPlayeralloc]initWithContentsOfURL:musicURL error:nil];

    thePlayer.volume = 5;

    self.player = thePlayer; 

 

posted @ 2012-12-16 16:44  言程序  阅读(204)  评论(0编辑  收藏  举报