Below is the code that I currently have. How do I enable inline media playback for swiftUI? I want the video to automatically play when the webview is appeared. Below is the code I have so far. Thanks in advance.
Button(action: {
self.isPlayed.toggle()//toggles the boolean isPlayed
self.appear.toggle()//toggles the boolean appear
}, label: {
//if the boolean of isPlayed and
if isPlayed && appear{
Image(systemName: "pause")
.font(Font.system(size: 30))
} else{
Image(systemName:"play")
.font(Font.system(size: 30))
}
})
Spacer()
}
if appear == true{
WebView(request: URLRequest(url: URL(string: "http:www.\(websites[counter])?playsinline=1")!))
.frame(width:300, height:300)
.padding()
.opacity(1)
}
}
}
}
struct WebView: UIViewRepresentable {
let request: URLRequest//pass the website to webkit
func makeUIView(context: Context) -> WKWebView {
return WKWebView()
}
func updateUIView(_ uiView: WKWebView, context: Context) {
uiView.load(request)
}
}