xcode - 我可以在 xcode 的不同文件夹中使用相同的文件名吗?如何使用 ios Swift 语言访问它

标签 xcode audio 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()

如何使用特定路径分别播放两个音频?

最佳答案

据我所知,如果您在项目中任何地方 有相似的文件名,无论在子文件夹中有多深,Xcode 都会提示重复资源。 当您按名称请求图像时,Xcode 会“看到”整个项目,这是好的一面。

简而言之,不,您不能在同一个项目中拥有两个同名的资源。建议给每个人起一个唯一的名字。

关于xcode - 我可以在 xcode 的不同文件夹中使用相同的文件名吗?如何使用 ios Swift 语言访问它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26838416/

相关文章:

jquery - jQuery-一次播放一个audioElement

swift - 在swift中创建通用变量字典

swift - 仅在 rx_tap 事件上调用方法

swift - Xcode升级后Core Data出现数据丢失

ios - 3 警告 AppIcon

c++ - 无名类或对象或函数,代码的含义

objective-c - Xcode - 删除的图像显示为交战

ios - 位码仍然可以在 Xcode 9.2 上禁用吗?

javascript - 尝试在单击按钮时播放随机图像和随机声音

java - Android RemoteController和Pandora