mp3文件没有流媒体但没有错误

时间:2015-06-25 21:53:14

标签: ios swift mp3 avplayer

这个文件不是作为mp3文件播放的,我不知道我在代码中搞砸了哪里。打印println语句。

let urlString = "http://anything2mp3.com/system/files/mp3/Siberian%20Husky%20gets%20ICE%20POOL%20Extended_q1zY1dp1_ig_youtube.mp3"


@IBAction func tempPlay(sender: AnyObject) {

    println("runningtemp")
    let url = NSURL(string: urlString)
    var avPlayer = AVPlayer(URL: url)
    avPlayer.play()
}

1 个答案:

答案 0 :(得分:0)

您只需要在IBAction中声明您的AVPlayer。

let urlString = "http://anything2mp3.com/system/files/mp3/Siberian%20Husky%20gets%20ICE%20POOL%20Extended_q1zY1dp1_ig_youtube.mp3"

var avPlayer:AVPlayer!

@IBAction func tempPlay(sender: AnyObject) {
    if let url = NSURL(string: urlString) {
        avPlayer = AVPlayer(URL: url)
        avPlayer.play()
    }
}