Add playback speed control

This commit is contained in:
Stephen Byatt 2021-06-26 11:26:33 +10:00
parent d1d44898e8
commit e37d944d97
3 changed files with 26 additions and 3 deletions

View File

@ -390,11 +390,11 @@
5310694F2684E7EE00CFFDBA /* VideoPlayer */ = {
isa = PBXGroup;
children = (
531069502684E7EE00CFFDBA /* InfoTabBarViewController.swift */,
531069512684E7EE00CFFDBA /* MediaInfoView.swift */,
531069522684E7EE00CFFDBA /* SubtitlesView.swift */,
531069532684E7EE00CFFDBA /* VideoPlayer.swift */,
531069542684E7EE00CFFDBA /* AudioView.swift */,
531069502684E7EE00CFFDBA /* InfoTabBarViewController.swift */,
531069532684E7EE00CFFDBA /* VideoPlayer.swift */,
531069552684E7EE00CFFDBA /* VideoPlayerViewController.swift */,
531069562684E7EE00CFFDBA /* VideoPlayerStoryboard.storyboard */,
);

View File

@ -67,12 +67,14 @@ class PlayerViewController: UIViewController, GCKDiscoveryManagerListener, GCKRe
}
var hasSentRemoteSeek: Bool = false
var selectedPlaybackSpeedIndex : Int = 3
var selectedAudioTrack: Int32 = -1
var selectedCaptionTrack: Int32 = -1
var playSessionId: String = ""
var lastProgressReportTime: Double = 0
var subtitleTrackArray: [Subtitle] = []
var audioTrackArray: [AudioTrack] = []
let playbackSpeeds : [Float] = [0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0]
var manifest: BaseItemDto = BaseItemDto()
var playbackItem = PlaybackItem()
@ -690,6 +692,11 @@ class PlayerViewController: UIViewController, GCKDiscoveryManagerListener, GCKRe
selectedAudioTrack = newTrackID
mediaPlayer.currentAudioTrackIndex = newTrackID
}
func playbackSpeedChanged(index: Int) {
selectedPlaybackSpeedIndex = index
mediaPlayer.rate = playbackSpeeds[index]
}
}
// MARK: - GCKGenericChannelDelegate

View File

@ -37,7 +37,8 @@ struct VideoPlayerSettings: View {
weak var delegate: PlayerViewController!
@State var captionTrack: Int32 = -99
@State var audioTrack: Int32 = -99
@State var playbackSpeedSelection : Int = 3
init(delegate: PlayerViewController) {
self.delegate = delegate
}
@ -60,6 +61,20 @@ struct VideoPlayerSettings: View {
}.onChange(of: audioTrack) { track in
self.delegate.audioTrackChanged(newTrackID: track)
}
Picker("Playback Speed", selection: $playbackSpeedSelection) {
ForEach(delegate.playbackSpeeds.indices, id: \.self) { speedIndex in
let speed = delegate.playbackSpeeds[speedIndex]
if floor(speed) == speed {
Text(String(format: "%.0fx", speed)).tag(speedIndex)
}
else {
Text(String(format: "%.2fx", speed)).tag(speedIndex)
}
}
}
.onChange(of: playbackSpeedSelection, perform: { index in
self.delegate.playbackSpeedChanged(index: index)
})
}.navigationBarTitleDisplayMode(.inline)
.navigationTitle("Audio & Captions")
.toolbar {
@ -80,6 +95,7 @@ struct VideoPlayerSettings: View {
.onAppear(perform: {
_captionTrack.wrappedValue = self.delegate.selectedCaptionTrack
_audioTrack.wrappedValue = self.delegate.selectedAudioTrack
playbackSpeedSelection = self.delegate.selectedPlaybackSpeedIndex
})
}
}