How to stream audio from URL without downloading mp3 file on device

后端 未结 5 576
挽巷
挽巷 2021-02-09 21:18

How would I stream audio from a URL in Swift without downloading the mp3 file on the device? What do I need to import? Do I need certain libraries? Add anything to the info.plis

5条回答
  •  清歌不尽
    2021-02-09 22:07

    For online streaming you have to use AVFoundation framework.

    var player: AVPlayer!
    
    let url = URL.init(string: "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3")
    player = AVPlayer.init(url: url!)
    

    To play:

        player.play()
    

    To pause:

        player.pause()
    

提交回复
热议问题