Skip to content

Commit

Permalink
Added playback speed to the video player
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Anderson committed Mar 15, 2024
1 parent 8d1b509 commit c8d0902
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Wasserflug-tvOS/SupplementalViews/VideoPlayerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ struct VideoPlayerView: UIViewControllerRepresentable {
])
let vc = AVPlayerViewController()
vc.delegate = context.coordinator
vc.speeds = viewModel.supportedSpeeds
vc.view.layoutIfNeeded() // This is needed or the OOTB speed controls don't display until you show the video for the second time
vc.transportBarCustomMenuItems = [createQualityAction()]
let playerItem = viewModel.createAVPlayerItem(desiredQuality: desiredQuality)

Expand Down
8 changes: 8 additions & 0 deletions Wasserflug-tvOS/ViewModels/VideoViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ class VideoViewModel: BaseViewModel, ObservableObject {
let contentPost: ContentPostV3Response
let description: AttributedString

let supportedSpeeds = [AVPlaybackSpeed(rate: 0.5, localizedName: "x0.5"),
AVPlaybackSpeed(rate: 0.75, localizedName: "x0.75"),
AVPlaybackSpeed(rate: 1.0, localizedName: "x1.0"),
AVPlaybackSpeed(rate: 1.25, localizedName: "x1.25"),
AVPlaybackSpeed(rate: 1.5, localizedName: "x1.5"),
AVPlaybackSpeed(rate: 1.75, localizedName: "x1.75"),
AVPlaybackSpeed(rate: 2.0, localizedName: "x2.0")]

var avMetadataItems: [AVMetadataItem] {
let desc = String(description.characters)

Expand Down

0 comments on commit c8d0902

Please sign in to comment.