iOS播放音效

创建播放器

// 资源的URL地址
NSURL *url = [[NSBundle mainBundle] URLForResource:@"mySong1.mp3" withExtension:nil];
// 创建播放器曲目
AVPlayerItem *playerItem = [[AVPlayerItem alloc] initWithURL:url];
// 创建播放器
AVPlayer *player = [[AVPlayer alloc] initWithPlayerItem:playerItem];

播放

[player play];

暂停

[player stop];

更换声音文件

AVPlayerItem *newPlayerItem = [[AVPlayerItem alloc] initWithURL:url];
[player replaceCurrentItemWithPlayerItem:newPlayerItem];

results matching ""

    No results matching ""