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

后端 未结 5 577
挽巷
挽巷 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:01

    I test it with your url and it work

        var player: AVPlayer?
        let url = "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3"
        let playerItem = AVPlayerItem( url:NSURL( string:url )! as URL )
        player = AVPlayer(playerItem:playerItem)
        player!.rate = 1.0;
    
            player!.play()
    

提交回复
热议问题