Code Block swift struct ContentView: View { @ObservedObject var player: Player = .shareInstance var body: some View { Button(action: { self.player.play() }) { Text("Play") } } } class Player: ObservableObject { static var shareInstance = Player() var audioPlayer: AVPlayer! func play() { guard let url = URL(string: "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3") else { print("Invalid url") return } let playerItem = AVPlayerItem(url: url) audioPlayer = AVPlayer(playerItem: playerItem) audioPlayer.play() } }
Warnings
Thanks2020-07-03 09:45:28.914989+0630 AudioPlayer[96225:4422734] [] nwprotocolgetquicimageblockinvoke dlopen libquic failed
2020-07-03 09:45:30.336438+0630 AudioPlayer[96225:4422744] [plugin] AddInstanceForFactory: No factory registered for id <CFUUID 0x600001f3a720> F8BB1C28-BAE8-11D6-9C31-00039315CD46
2020-07-03 09:45:30.482683+0630 AudioPlayer[96225:4422869] HALBIOBufferManagerClient::GetIOBuffer: the stream index is out of range
2020-07-03 09:45:30.483346+0630 AudioPlayer[96225:4422869] HALBIOBufferManagerClient::GetIOBuffer: the stream index is out of range
2020-07-03 09:45:30.495630+0630 AudioPlayer[96225:4422869] [aqme] 255: AQDefaultDevice (1): output stream 0: null buffer
2020-07-03 09:45:30.496099+0630 AudioPlayer[96225:4422869] [aqme] 1778: EXCEPTION thrown (-50): error != 0
2020-07-03 09:45:45.485455+0630 AudioPlayer[96225:4422744] [aqme] 182: timed out after 15.000s (0 1); suspension count=0 (IOSuspensions: )
2020-07-03 09:45:45.486826+0630 AudioPlayer[96225:4422744] 244: CAUISoundClientBase::StartPlaying: AddRunningClient failed (status = -66681).
2020-07-03 09:45:45.615673+0630 AudioPlayer[96225:4422989] HALBIOBufferManagerClient::GetIOBuffer: the stream index is out of range
2020-07-03 09:45:45.616021+0630 AudioPlayer[96225:4422989] HALBIOBufferManager_Client::GetIOBuffer: the stream index is out of range
2020-07-03 09:45:45.628154+0630 AudioPlayer[96225:4422989] [aqme] 255: AQDefaultDevice (1): output stream 0: null buffer
2020-07-03 09:45:45.628978+0630 AudioPlayer[96225:4422989] [aqme] 1778: EXCEPTION thrown (-50): error != 0
2020-07-03 09:46:00.617994+0630 AudioPlayer[96225:4422986] [aqme] 182: timed out after 15.000s (1 2); suspension count=0 (IOSuspensions: )