Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions HackerTube/Domain/UserDefaultsKey.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// UserDefaultsKey.swift
// HackerTube
//
// Created by Mathijs Bernson on 11/08/2025.
//

import Foundation

enum UserDefaultsKey: String {
case playbackRate = "playbackRate"
}
2 changes: 2 additions & 0 deletions HackerTube/Features/Talk/TalkPlayerViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ final class TalkPlayerViewModel {
subsystem: Bundle.main.bundleIdentifier!, category: "TalkPlayerViewModel")

func prepareForPlayback(recording: Recording, talk: Talk) async {
player.defaultRate = UserDefaults.standard.float(forKey: UserDefaultsKey.playbackRate.rawValue)

let playerItem = AVPlayerItem(url: recording.recordingURL)
playerItem.externalMetadata = factory.createMetadataItems(for: recording, talk: talk)

Expand Down
12 changes: 12 additions & 0 deletions HackerTube/Features/VideoPlayer/VideoPlayerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ class VideoPlayerCoordinator: NSObject, AVPlayerViewControllerDelegate {
}

class VideoPlayerViewController: AVPlayerViewController {
private var selectedSpeedObserver: NSKeyValueObservation?

override func viewDidLoad() {
super.viewDidLoad()

selectedSpeedObserver = self.observe(\.selectedSpeed, options: [.new]) { controller, change in
if let selectedSpeed = change.newValue.flatMap({ $0 }) {
UserDefaults.standard.set(selectedSpeed.rate, forKey: UserDefaultsKey.playbackRate.rawValue)
}
}
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)

Expand Down
2 changes: 2 additions & 0 deletions HackerTube/HackerTubeApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import CCCApi

@main
struct HackerTubeApp: App {
@UIApplicationDelegateAdaptor var appDelegate: HackerTubeAppDelegate

var body: some Scene {
WindowGroup {
ContentView()
Expand Down
21 changes: 21 additions & 0 deletions HackerTube/HackerTubeAppDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// HackerTubeAppDelegate.swift
// HackerTube
//
// Created by Mathijs Bernson on 11/08/2025.
//

import UIKit

class HackerTubeAppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
registerDefaultSettings()
return true
}

private func registerDefaultSettings() {
UserDefaults.standard.register(defaults: [
UserDefaultsKey.playbackRate.rawValue : 1.0 as Float,
])
}
}
Loading