avplayer

AVPlayer audioSessionGotInterrupted notification when waking up from background

戏子无情 提交于 2020-08-21 18:40:05
问题 I use AVAudioPlayer to play audio. I have background audio enabled and the audio sessions are configured correctly. I implemented the audioSessionGotInterrupted method to be informed if the audio session gets interrupted. This is my current code: @objc private func audioSessionGotInterrupted(note: NSNotification) { guard let userInfo = note.userInfo, let typeValue = userInfo[AVAudioSessionInterruptionTypeKey] as? UInt, let type = AVAudioSessionInterruptionType(rawValue: typeValue) else {

AVPlayer audioSessionGotInterrupted notification when waking up from background

拥有回忆 提交于 2020-08-21 18:39:47
问题 I use AVAudioPlayer to play audio. I have background audio enabled and the audio sessions are configured correctly. I implemented the audioSessionGotInterrupted method to be informed if the audio session gets interrupted. This is my current code: @objc private func audioSessionGotInterrupted(note: NSNotification) { guard let userInfo = note.userInfo, let typeValue = userInfo[AVAudioSessionInterruptionTypeKey] as? UInt, let type = AVAudioSessionInterruptionType(rawValue: typeValue) else {

Get AVPlayerItem track title with SwiftUI

此生再无相见时 提交于 2020-08-05 13:33:58
问题 I'm trying to create a radio app, which streams audio from an http streaming. I'm trying to fetch the current playing track title from the streaming, but all I can find is deprecated methods. My model looks like this: struct RadioStreamer { let streamingURL: URL private let player: AVPlayer? private let playerItem: AVPlayerItem? init(streamingURL: URL) { self.streamingURL = streamingURL self.playerItem = AVPlayerItem(url: self.streamingURL) self.player = AVPlayer(playerItem: self.playerItem)