BLACK FRIDAY: Save 50% on all books and bundles! >>

Play a video

Forums > SwiftUI

I am having a problem playing a video. Here is my example code

import AVKit
import SwiftUI

struct ContentView: View {
    var body: some View {
        VideoPlayer(player: AVPlayer(url: URL(string: "")!))

When the program runs, I just get the video controls shown, but a blank video. Some other videos play OK. Any ideas? My iPhone is running 14.0


@twostraws  Site AdminHWS+

I'm not sure you're able to embed YouTube videos like that – IIRC they serve them up in a format iOS doesn't support without special permissions from Apple. Perhaps try a direct MP4 link first and see if that's better.


the problem is that I get the URL from this API call


could i perhaps embed a web browser control and play a video inside that?


Yes I tried with local m4v files, its showing black screen. Tried mp4 file it shows the video thumbnail but no controls, does not play. A remote url works but not youtube video. I need to play local m4v files. Also how to programmatically play the video in swiftUI and also add flag overlays as this is a test.


could i perhaps embed a web browser control and play a video inside that?


Sure, the WKWebView will work great. I dont think you could play that YT link natively without trying to get link to the underling files...


Save 50% in my Black Friday sale.

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

Unknown user

Not logged in

Log in

Link copied to your pasteboard.