AVPlayer And Local Files

后端 未结 6 1636
名媛妹妹
名媛妹妹 2020-12-01 03:21

I am building a MP3 player for iOS that plays audio files hosted on the web. I want to offer the ability to play the files offline so I have the files downloading using ASIH

6条回答
  •  广开言路
    2020-12-01 03:37

    Swift local playback version, assuming I have a file "shelter.mp3" in my bundle:

    @IBAction func button(_ sender: Any?) {
        guard let url = Bundle.main.url(forResource: "shelter", withExtension: "mp3") else {
            return
        }
    
        let player = AVPlayer(url: url)
    
        player.play()
        playerView?.player = player;
    }
    

    See here for details about playerView or playing a remote url.

提交回复
热议问题