UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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,

3      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

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.