2014-09-23 81 views
0

聲音開始它不會停止, 我該如何阻止它?iOS Swift;停止AVFoundation重複

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

,但它不工作

回答

0

使用AVPlayer:

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