Skip to content

Commit

Permalink
feat: play video frame by frame
Browse files Browse the repository at this point in the history
  • Loading branch information
godly-devotion committed Apr 2, 2024
1 parent e6e400e commit bc3b88e
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
56 changes: 56 additions & 0 deletions Front Row/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -2475,6 +2475,34 @@
}
}
},
"Next Frame" : {
"localizations" : {
"ja" : {
"stringUnit" : {
"state" : "translated",
"value" : "次のフレームへ"
}
},
"ko" : {
"stringUnit" : {
"state" : "translated",
"value" : "다음 프레임"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "下一帧"
}
},
"zh-Hant" : {
"stringUnit" : {
"state" : "translated",
"value" : "下一個影格"
}
}
}
},
"None" : {
"localizations" : {
"ar" : {
Expand Down Expand Up @@ -3471,6 +3499,34 @@
}
}
},
"Previous Frame" : {
"localizations" : {
"ja" : {
"stringUnit" : {
"state" : "translated",
"value" : "前のフレームへ"
}
},
"ko" : {
"stringUnit" : {
"state" : "translated",
"value" : "이전 프레임"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "上一帧"
}
},
"zh-Hant" : {
"stringUnit" : {
"state" : "translated",
"value" : "上一個影格"
}
}
}
},
"Report a Problem" : {
"localizations" : {
"ja" : {
Expand Down
16 changes: 16 additions & 0 deletions Front Row/Main Menu/PlaybackCommands.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,22 @@ struct PlaybackCommands: Commands {

Divider()

Button {
Task { await playEngine.frameStep(1) }
} label: {
Text("Next Frame")
}
.keyboardShortcut(".", modifiers: [])
.disabled(!playEngine.isLoaded || presentedViewManager.isPresenting)

Button {
Task { await playEngine.frameStep(-1) }
} label: {
Text("Previous Frame")
}
.keyboardShortcut(",", modifiers: [])
.disabled(!playEngine.isLoaded || presentedViewManager.isPresenting)

Button {
Task { await playEngine.goForwards() }
} label: {
Expand Down
7 changes: 7 additions & 0 deletions Front Row/Support/PlayEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,13 @@ import SwiftUI
await player.seek(to: time, toleranceBefore: .zero, toleranceAfter: .zero)
}

@MainActor
func frameStep(_ byCount: Int) {
guard let item = player.currentItem else { return }

item.step(byCount: byCount)
}

func fitToVideoSize() {
guard let window = NSApp.windows.first else { return }
guard videoSize != CGSize.zero else {
Expand Down

0 comments on commit bc3b88e

Please sign in to comment.