循环背景音乐? [英] Loop background music?

查看:172
本文介绍了循环背景音乐?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  1. 为我的iOS游戏播放背景音乐的最佳方式是什么?我该怎么做?

  1. What's the best way of playing background music for my iOS game? And how do I do this?

将音乐文件用于播放的最佳格式是什么?

What's the best format of having that music file in for playback?

这首歌是否会在整个游戏中愉快地播放,更改视图时不会中断?

Will this this song happily play through the entire game, no interruptions when changing view?

如何循环播放此音乐?


推荐答案

你可以使用 AVAudioPlayer

NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"mySound" ofType:@"mp3"];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:nil];
player.numberOfLoops = -1; //infinite

[player play];

您可以通过设置 currentTime :

player.currentTime = 10; //jump to 10th second

这篇关于循环背景音乐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆