Swiftui:设备锁定时保持视频播放器
据我所知,标题说明了这一切。我有以下视图:
struct VideoView: View{
@State var FilePath = ""
@State private var player = AVPlayer()
var body: some View{
VideoPlayer(player: player)
.onAppear{
player = AVPlayer(url: URL(string: FilePath)!)
player.play()
}.onDisappear{
player.pause()
}
}
}
我在ContentView中调用此视图,并且可以正常工作。但是,当我关闭应用程序或设备锁定时,视频会停止播放。有没有办法更改它以使其继续播放?
title says it all as far as I'm aware. I have the following view:
struct VideoView: View{
@State var FilePath = ""
@State private var player = AVPlayer()
var body: some View{
VideoPlayer(player: player)
.onAppear{
player = AVPlayer(url: URL(string: FilePath)!)
player.play()
}.onDisappear{
player.pause()
}
}
}
I'm calling this in my ContentView, and it works fine. But when I close the app, or when the device is locked, the video stops playback. Is there a way that I can change this so that it will keep playing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(1)
花了一段时间才弄清楚,但我最终提出了以下解决方案。
音频,播放和图片
签名和能力avplayer
时,添加以下代码:It took a while to figure it out, but I eventually came up with the following solution.
Audio, AirPlay and Picture in Picture
underSigning and Capabilities
AVPlayer
, add the following code: