iOS Swift;停止AVFoundation重复

时间:2014-09-23 06:11:09

标签: ios swift

声音开始时它不会停止, 我怎么能阻止它?

import AVFoundation

var audioPlayer2 = AVAudioPlayer()
var Sound2 = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("filename", ofType: "aiff")!)


override func viewDidLoad() {
    super.viewDidLoad()
    audioPlayer2 = AVAudioPlayer(contentsOfURL: Sound2, error: nil)
    audioPlayer2.prepareToPlay()    }

fund update() { ~ ~ ~ ~

audioPlayer2.play()

}

我试过

audioPlayer2.stop()

但它不起作用

1 个答案:

答案 0 :(得分:0)

使用AVPlayer:

var player:AVPlayer!
var steamingURL:NSURL = NSURL(string:playerURL)
player = AVPlayer(URL: steamingURL)
player.play()