FREE TRIAL: Accelerate your app development career with Hacking with Swift+! >>

How to Implement SwiftUI Media Controls into the Touch Bar

Forums > macOS


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: "")

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {

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()
        return wkWebview

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




Hacking with Swift is sponsored by Sentry

SPONSORED With Sentry’s error and performance monitoring for iOS you see mobile vitals that actually matter, can solve any latency issues quickly, and learn how each release is performing over time.

Get started

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

You are not logged in

Log in or create account

Link copied to your pasteboard.