Play Audio iOS Objective-C

后端 未结 7 1292
南旧
南旧 2020-11-30 00:25

I\'m trying to get an audio file playing in my iOS app. This is my current code

NSString *soundFilePath = [NSString stringWithFormat:@\"%@/test.m4a\", [[NSBu         


        
7条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-30 00:32

    Swift 4.2

    var soundFilePath = "\(Bundle.main.resourcePath ?? "")/test.m4a"
    var soundFileURL = URL(fileURLWithPath: soundFilePath)
    
    var player = try? AVAudioPlayer(contentsOf: soundFileURL)
    player?.numberOfLoops = -1 //Infinite
    
    player?.play()
    

提交回复
热议问题