相关疑难解决方法(0)

让AVAudioEngine重复一个声音

我一直无法使下面的代码一遍又一遍地重复audioURL的声音.现在它只是在视图打开时播放一次,然后停止.

import UIKit
import AVFoundation
class aboutViewController: UIViewController {

    var audioUrl = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("chimes", ofType: "wav")!)
    var audioEngine = AVAudioEngine()
    var myPlayer = AVAudioPlayerNode()

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.

        audioEngine.attachNode(myPlayer)
        var audioFile = AVAudioFile(forReading: audioUrl, error: nil)
        var audioError: NSError?
        audioEngine.connect(myPlayer, to: audioEngine.mainMixerNode, format: audioFile.processingFormat)
        myPlayer.scheduleFile(audioFile, atTime: nil, completionHandler: nil)
        audioEngine.startAndReturnError(&audioError)
        myPlayer.play()


    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}
Run Code Online (Sandbox Code Playgroud)

谢谢!

ios swift

7
推荐指数
1
解决办法
2306
查看次数

标签 统计

ios ×1

swift ×1