Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 应用程序从暂停状态返回后,AVPlayer不会播放_Swift_Avplayer_Avplayeritem_Avqueueplayer - Fatal编程技术网

Swift 应用程序从暂停状态返回后,AVPlayer不会播放

Swift 应用程序从暂停状态返回后,AVPlayer不会播放,swift,avplayer,avplayeritem,avqueueplayer,Swift,Avplayer,Avplayeritem,Avqueueplayer,我有一个AVQueuePlayer,除了从挂起状态返回后,它按预期工作 它正在播放HLS音频流。我的暂停按钮的逻辑非常简单 isPlaying ? player?.play() : player?.pause() 我已经检查了播放器和当前项目的状态,所有这些都显示它正在“播放”。但音频不会进行播放或播放 player.rate = 1 player.currentItem.asset.isPlayable = true player.status == readyToPlay player.c

我有一个AVQueuePlayer,除了从挂起状态返回后,它按预期工作

它正在播放HLS音频流。我的暂停按钮的逻辑非常简单

isPlaying ? player?.play() : player?.pause()
我已经检查了播放器和当前项目的状态,所有这些都显示它正在“播放”。但音频不会进行播放或播放

player.rate = 1
player.currentItem.asset.isPlayable = true
player.status == readyToPlay
player.currentItem.status == readyToPlay
我还将在课程中设置以下内容:

do {
    try session.setCategory(AVAudioSession.Category.playback, options: [])
    try session.setActive(true, options: [])
} catch {
    print("Failed to set session active")
}

如果您有任何关于如何解决此问题的建议,我们将不胜感激。我是否需要跟踪应用程序进入暂停状态并重新加载AVPlayerItem

我是否需要跟踪应用程序进入暂停状态并重新加载AVPlayerItem


你需要跟踪的不是应用程序的暂停;这是音频会话的中断。AVAudioSession提供的通知正是出于此目的。

请参阅Thank@matt。我尝试过中断处理程序,但我确实看到它在从暂停状态恢复后启动。我确实让它工作了,但感觉有点不舒服。我正在抓取当前经过的时间,重新初始化播放器,并试图将其恢复到经过的时间。我不明白这有什么不妥。你流着水,所有的东西都被冲洗了,所以很明显你必须做点什么才能重新开始。