本文摘自:http://www.cocoachina.com/bbs/read.php?tid=73570&page=1
制作播放器:
代码如下:
2、播放音乐:
-(
void
) playMusic
{
@try {
//取文件路径
NSString *musicFilePath = [[ NSBundle mainBundle ] pathForResource : @"startLogo" ofType : @"mp3" ];
NSURL *musicURL = [[ NSURL alloc ] initFileURLWithPath :musicFilePath];
musicPlayer = [[ AVAudioPlayer alloc ] initWithContentsOfURL :musicURL error : nil ];
[musicURL release ];
//[musicPlayer prepareToPlay];
//[musicPlayer setVolume:1]; //设置音量大小
musicPlayer . numberOfLoops = 0 ; //设置播放次数,-1为一直循环,0为一次
[ musicPlayer play ];
}
@catch ( NSException * e) {
}
}
{
@try {
//取文件路径
NSString *musicFilePath = [[ NSBundle mainBundle ] pathForResource : @"startLogo" ofType : @"mp3" ];
NSURL *musicURL = [[ NSURL alloc ] initFileURLWithPath :musicFilePath];
musicPlayer = [[ AVAudioPlayer alloc ] initWithContentsOfURL :musicURL error : nil ];
[musicURL release ];
//[musicPlayer prepareToPlay];
//[musicPlayer setVolume:1]; //设置音量大小
musicPlayer . numberOfLoops = 0 ; //设置播放次数,-1为一直循环,0为一次
[ musicPlayer play ];
}
@catch ( NSException * e) {
}
}