Avplayer没有玩swift 3(Xcode 8)

时间:2016-10-26 19:21:21

标签: swift3 avplayer ios10

请帮我记录播放但没有听到声音

    .syntax unified
    .text
    .global _funcPtr
    .p2align 2
    .global _myAsmFunc
    .type _myAsmFunc, %function
_myAsmFunc:
    @ Load the address of _funcPtr to X1 here

2 个答案:

答案 0 :(得分:3)

您需要将播放器分配给不超出范围的变量,例如

class ViewControllerA: UIViewController {

    var avPlayer: AVPlayer!

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view
    }

    override func viewDidAppear(_ animated: Bool) {
        let videoURL = NSURL(string: "https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")
        avPlayer = AVPlayer(url: videoURL! as URL)
        let playerLayer = AVPlayerLayer(player: avPlayer)
        playerLayer.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.width * 3.0 / 4.0)
        self.view.layer.addSublayer(playerLayer)
        avPlayer.play()
    }
}

答案 1 :(得分:0)

之前声明播放器变量
 var playerT : AVPlayer!

现在你可以从网址播放歌曲了

let url = URL(string: "https://s3.amazonaws.com/kargopolov/BlueCafe.mp3")

                playerT = AVPlayer(url: url!)
                playerT.volume = 1.0
                playerT.play()

                if playerT.rate != 0 && playerT.error == nil{
                    print("Playing")
                }else{
                    print("Error Playing")
                }