BLACK FRIDAY SALE: Save big on all my Swift books and bundles! >>

How to Implement SwiftUI Media Controls into the Touch Bar

Forums > SwiftUI

Hi,

I'm pretty new to SwiftUI and Swift and I'm trying to create a macOS app that uses WKWebView to display Netflix. I want it to be similar to the Clicker for Netflix app. So far, I’ve been successful in displaying Netflix. Now I want to add media controls to play or pause the Netflix movie from the Touch Bar in addition to skipping to the next episode of a TV show. I'm not sure how to start implementing these features. I’ve looked at using AVKit but haven’t gotten much far. I would really appreciate it if you could help me. The following is my ContentView.swift file:

import SwiftUI
import WebKit

struct ContentView: View {
    var body: some View {
            Webview(url: "https://www.netflix.com")
                .scaledToFill()
        }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

And this is the WebView.swift file:

import Foundation
import SwiftUI
import WebKit

struct Webview: NSViewRepresentable {

    var url: String

    func makeNSView(context: Context) -> WKWebView {
        guard let url = URL(string: self.url) else {
            return WKWebView()
        }

        let request = URLRequest(url: url)
        let wkWebview = WKWebView()
        wkWebview.load(request)
        return wkWebview
    }

    func updateNSView(_ nsView: WKWebView, context: Context) {

    }
}

Thanks,

1      

Hacking with Swift is sponsored by RevenueCat

SPONSORED In-app subscriptions are a pain to implement, hard to test, and full of edge cases. RevenueCat makes it straightforward and reliable so you can get back to building your app. Oh, and it's free if your app makes less than $10k/mo.

Learn more

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

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.