IOS 播放音乐实例

作者:朱克锋

邮箱:[email protected]

转载请注明出处:http://blog.csdn.net/linux_zkf


- (BOOL) prepAudio

{

NSError *error;

NSString *path = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"mp3"];

if (![[NSFileManager defaultManager] fileExistsAtPath:path]) 

{

return NO;

}

self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:&error];

if (!self.player)

{

NSLog(@"Error: %@", [error localizedDescription]);

return NO;

}

[self.player prepareToPlay];

return YES;

}

- (void) play

{

[self.player play];

}

- (void) pause

{

[self.player pause];

}

- (void) stop

{

[self.player stop];

}

你可能感兴趣的:(ios,音乐,Path)