Can I use the same filename in a different folder in xcode and how can I access it in ios Swift language?

I am working on an audio player in iOS 8 in Swift language.

I have an audio file name with "apple.mp3" in both male and female voices, with the same audio name. Both files are two different groups, for the male male group and the female female group. So the path would be male / apple .mp3 and female / apple .mp3.

I am using the following code to play an audio file

    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()

      

How can I play both audio separately with a specific path?

+3


source to share


1 answer


As far as I know, if you have similar filenames anywhere in the project, no matter how deep in the subfolder, Xcode will complain about duplicate resources. When you ask for an image by name, Xcode "sees" the entire project at the top.



In short, no, you cannot have two resources with the same name in the same project. It is recommended that you provide a unique name for each one.

+3


source







All Articles