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

How to Implement SwiftUI Media Controls into the Touch Bar

Forums > macOS

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      

Save 50% in my Black Friday sale.

SAVE 50% To celebrate Black Friday, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

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.