How to stream remote audio in iOS 13? (SwiftUI)

后端 未结 1 1690
长情又很酷
长情又很酷 2020-12-20 05:26

This code using AVPlayer works only on Playground

import AVFoundation

    var player = AVPlayer()
let playerItem = AVPlayerIte         


        
相关标签:
1条回答
  • 2020-12-20 05:56

    In SwiftUI, Views are value types. They are only data that describe the things on screen. They can be created or destroyed or copied at any time. AVPlayer is a reference to a specific player object. You're assuming here that it will continue to exist, and there will only be one of them. That's not something that a SwiftUI View provides.

    You need to move your AVPlayer outside of the View (into Model objects), and just bind UI actions to it.

    0 讨论(0)
提交回复
热议问题