播放音乐

 -(void) playMusic
{
@try{
//取文件路径
NSString *musicFilePath = [[NSBundle mainBundle] pathForResource:@"startLogo" ofType:@"mp3"];       
NSURL *musicURL = [[NSURL alloc] initFileURLWithPath:musicFilePath];  
musicPlayer= [[AVAudioPlayeralloc] initWithContentsOfURL:musicURL error:nil];
[musicURL release];
//[musicPlayer prepareToPlay];
//[musicPlayer setVolume:1];            //设置音量大小
musicPlayer.numberOfLoops= 0; //设置播放次数,-1为一直循环,0为一次
[musicPlayerplay];
}
@catch(NSException* e) {
}
}

你可能感兴趣的:(播放音乐)