iphone 制作播放器

本文摘自:http://www.cocoachina.com/bbs/read.php?tid=73570&page=1 

制作播放器:

代码如下:

 2、播放音乐:

-(void) playMusic
{
@try{
//取文件路径
NSString *musicFilePath = [[NSBundle mainBundlepathForResource:@"startLogo" ofType:@"mp3"];       
NSURL *musicURL = [[NSURL allocinitFileURLWithPath:musicFilePath];  
musicPlayer= [[AVAudioPlayerallocinitWithContentsOfURL:musicURL error:nil];
[musicURL release];
//[musicPlayer prepareToPlay];
//[musicPlayer setVolume:1];            //设置音量大小
musicPlayer.numberOfLoops0//设置播放次数,-1为一直循环,0为一次
[musicPlayerplay]; 
}
@catch(NSException* e) {
}
posted on 2011-11-06 17:00  wtq  阅读(256)  评论(0编辑  收藏  举报