2 years ago

#43380

test-img

Henny C

Swift UI - Embed Video Unavailable

I am still fairly new with using SwiftUI. I am creating my first app and I was trying to embed a youtube video into my app, but I keep running into this problem where the video is automatically unavailable for whatever reason. Here is my code down below. Im not totally sure what I did wrong.

struct VideoView: UIViewRepresentable{

let videoID: String

func makeUIView(context: Context) -> WKWebView {
    return WKWebView()
}

func updateUIView(_ uiView: WKWebView, context: Context) {
    guard let youtubeURL = URL (string: "https://www.youtube.com/embed/\(videoID)")
    else {
        return
    }
    uiView.scrollView.isScrollEnabled = false
    uiView.load(URLRequest(url: youtubeURL))
}

}

Some Pictures down below:

The Outcome

Code 1

Code 2

swift

swiftui

embed

0 Answers

Your Answer

Accepted video resources