sud*_*eer 5 audio xcode swift ios8
我正在使用Swift语言在iOS 8中开发音频播放器。
我在男性和女性语音中都有一个带有“ apple.mp3”的音频文件名称,并且具有相同的音频名称。这两个文件是两个不同的组,男性组和女性音频组。因此路径将是male / apple.mp3和female / apple.mp3。
我正在使用以下代码播放音频文件
var audioPlayer = AVAudioPlayer()
var currentAudioPath:NSURL!
currentAudioPath = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource(audioName, ofType: "mp3")!)
AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, error: nil)
AVAudioSession.sharedInstance().setActive(true, error: nil)
UIApplication.sharedApplication().beginReceivingRemoteControlEvents()
audioPlayer = AVAudioPlayer(contentsOfURL: currentAudioPath, error: nil)
audioPlayer.delegate = self
audioPlayer.play()
audioPlayer.prepareToPlay()
Run Code Online (Sandbox Code Playgroud)
如何使用特定路径分别播放两个音频?
据我所知,如果您在项目中的任何地方都有类似的文件名,则无论子文件夹中的文件有多深,Xcode都会抱怨重复的资源。当您要求提供名称的图像时,Xcode会“看到”整个项目,这是好的一面。
简而言之,不可以,同一项目中不能有两个具有相同名称的资源。建议给每个名称一个唯一的名称。
| 归档时间: |
|
| 查看次数: |
1076 次 |
| 最近记录: |