你好,我有一些代码,可以加载一个网络视频到一个swift的用户界面视图,并允许它播放。目前,视频自动播放时,它加载,我想停止这种行为。此外,视频只能在全屏模式下观看,我不知道如何使它可以发挥,而不是在全屏。我还收到警告“获取Assert时出错:<Error Domain=RBSServiceErrorDomain Code=1“(originator doesn't have entitlement com.apple.runningboard.assertions.webkit AND originator doesn't have entitlement”I tried the line“webView.configuration.allowsInlineMediaPlayback = true”to allow the video to play while not being full sized and it doesn't work.如果有人知道如何让这2件功能的工作,我会很感激,谢谢。
import SwiftUI
import WebKit
struct YouTubeView: UIViewRepresentable {
let videoId: String
func makeUIView(context: Context) -> WKWebView {
let webView = WKWebView()
webView.configuration.allowsInlineMediaPlayback = true
webView.configuration.mediaTypesRequiringUserActionForPlayback = []
return webView
}
func updateUIView(_ uiView: WKWebView, context: Context) {
guard let demoURL = URL(string: "https://s1.fwmrm.net/m/1/169843/20/89977492/AIDP7266000H_ENT_MEZZ_HULU_8166176_578.mp4") else { return }
uiView.scrollView.isScrollEnabled = false
uiView.load(URLRequest(url: demoURL))
}
}
struct VideoPlayerView: View {
var ids = "hzls6ZUHCYM"
var body: some View {
ZStack {
ScrollView(showsIndicators: false) {
VStack {
YouTubeView(videoId: ids)
.frame(width: 300, height: 175)
}
}
}
}
}
1条答案
按热度按时间qvtsj1bj1#
尝试加载你的视频嵌入在html而不是直接到一个mp4网址.设置
video
标记的playsinline
参数。在示例化WKWebView
对象之前也设置allowsInlineMediaPlayback
。至于授权错误,other SO answers似乎表明这可以简单地忽略。