fix video being out of sync
This commit is contained in:
@@ -9,7 +9,7 @@ import Foundation
|
||||
|
||||
class CurrentWorkoutInfo {
|
||||
var supersetIndex: Int = 0
|
||||
var exerciseIndex: Int = 0
|
||||
var exerciseIndex: Int = -1
|
||||
var workout: Workout?
|
||||
var complete: (() -> Void)?
|
||||
|
||||
@@ -38,34 +38,18 @@ class CurrentWorkoutInfo {
|
||||
return obj
|
||||
}
|
||||
|
||||
// this is setting nothing so we can half ass it
|
||||
var nextExerciseInfo: SupersetExercise? {
|
||||
guard let workout = workout else { return nil }
|
||||
guard let supersets = workout.supersets else { return nil }
|
||||
|
||||
var _exerciseIndex = exerciseIndex + 1
|
||||
var _supersetIndex = supersetIndex
|
||||
let currentSuperSet = supersets[_supersetIndex]
|
||||
|
||||
if _exerciseIndex >= currentSuperSet.exercises.count {
|
||||
var _currentRound = currentRound + 1
|
||||
|
||||
if currentRound > currentSuperSet.rounds {
|
||||
_supersetIndex = _supersetIndex + 1
|
||||
_currentRound = 1
|
||||
|
||||
if supersetIndex >= supersets.count {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
_exerciseIndex = 0
|
||||
let _exerciseIndex = allSupersetExecerciseIndex + 1
|
||||
if _exerciseIndex >= workout.allSupersetExecercise?.count ?? -1 {
|
||||
return nil
|
||||
}
|
||||
|
||||
let superset = supersets[_supersetIndex]
|
||||
let exercise = superset.exercises[_exerciseIndex]
|
||||
return exercise
|
||||
return workout.allSupersetExecercise?[_exerciseIndex]
|
||||
}
|
||||
|
||||
// this needs to set stuff for iphone
|
||||
var nextExercise: SupersetExercise? {
|
||||
guard let workout = workout else { return nil }
|
||||
guard let supersets = workout.supersets else { return nil }
|
||||
|
||||
@@ -74,55 +74,11 @@ struct ExternalWorkoutDetailView: View {
|
||||
.scaledToFill()
|
||||
}
|
||||
}
|
||||
.onChange(of: bridgeModule.isInWorkout, perform: { newValue in
|
||||
if let currentExtercise = bridgeModule.currentExerciseInfo.currentExercise {
|
||||
if let videoURL = VideoURLCreator.videoURL(
|
||||
thotStyle: extThotStyle,
|
||||
gender: thotGenderOption,
|
||||
defaultVideoURLStr: currentExtercise.exercise.videoURL,
|
||||
exerciseName: currentExtercise.exercise.name,
|
||||
workout: bridgeModule.currentExerciseInfo.workout) {
|
||||
avPlayer = AVPlayer(url: videoURL)
|
||||
avPlayer.play()
|
||||
|
||||
if extShowNextVideo {
|
||||
if let smallVideoURL = VideoURLCreator.videoURL(
|
||||
thotStyle: VideoURLCreator.otherVideoType(forVideoURL: videoURL),
|
||||
gender: thotGenderOption,
|
||||
defaultVideoURLStr: currentExtercise.exercise.videoURL,
|
||||
exerciseName: currentExtercise.exercise.name,
|
||||
workout: bridgeModule.currentExerciseInfo.workout) {
|
||||
smallAVPlayer = AVPlayer(url: smallVideoURL)
|
||||
smallAVPlayer.play()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.onChange(of: bridgeModule.isInWorkout, perform: { _ in
|
||||
playVideos()
|
||||
})
|
||||
.onChange(of: bridgeModule.currentExerciseInfo.exerciseIndex, perform: { newValue in
|
||||
if let currentExtercise = bridgeModule.currentExerciseInfo.currentExercise {
|
||||
if let videoURL = VideoURLCreator.videoURL(
|
||||
thotStyle: extThotStyle,
|
||||
gender: thotGenderOption,
|
||||
defaultVideoURLStr: currentExtercise.exercise.videoURL,
|
||||
exerciseName: currentExtercise.exercise.name,
|
||||
workout: bridgeModule.currentExerciseInfo.workout) {
|
||||
avPlayer = AVPlayer(url: videoURL)
|
||||
avPlayer.play()
|
||||
|
||||
if extShowNextVideo {
|
||||
if let smallVideoURL = VideoURLCreator.videoURL(
|
||||
thotStyle: .never,
|
||||
gender: thotGenderOption,
|
||||
defaultVideoURLStr: BridgeModule.shared.currentExerciseInfo.nextExerciseInfo?.exercise.videoURL,
|
||||
exerciseName: BridgeModule.shared.currentExerciseInfo.nextExerciseInfo?.exercise.name,
|
||||
workout: bridgeModule.currentExerciseInfo.workout) {
|
||||
smallAVPlayer = AVPlayer(url: smallVideoURL)
|
||||
smallAVPlayer.play()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.onChange(of: bridgeModule.currentExerciseInfo.allSupersetExecerciseIndex, perform: { _ in
|
||||
playVideos()
|
||||
})
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
.background(bridgeModule.currentExerciseInfo.workout == nil ? Color(red: 157/255, green: 138/255, blue: 255/255) : Color(uiColor: .systemBackground))
|
||||
@@ -132,6 +88,31 @@ struct ExternalWorkoutDetailView: View {
|
||||
smallAVPlayer.play()
|
||||
}
|
||||
}
|
||||
|
||||
func playVideos() {
|
||||
if let currentExtercise = bridgeModule.currentExerciseInfo.currentExercise {
|
||||
if let videoURL = VideoURLCreator.videoURL(
|
||||
thotStyle: extThotStyle,
|
||||
gender: thotGenderOption,
|
||||
defaultVideoURLStr: currentExtercise.exercise.videoURL,
|
||||
exerciseName: currentExtercise.exercise.name,
|
||||
workout: bridgeModule.currentExerciseInfo.workout) {
|
||||
avPlayer = AVPlayer(url: videoURL)
|
||||
avPlayer.play()
|
||||
}
|
||||
|
||||
if let smallVideoURL = VideoURLCreator.videoURL(
|
||||
thotStyle: .never,
|
||||
gender: thotGenderOption,
|
||||
defaultVideoURLStr: BridgeModule.shared.currentExerciseInfo.nextExerciseInfo?.exercise.videoURL,
|
||||
exerciseName: BridgeModule.shared.currentExerciseInfo.nextExerciseInfo?.exercise.name,
|
||||
workout: bridgeModule.currentExerciseInfo.workout),
|
||||
extShowNextVideo {
|
||||
smallAVPlayer = AVPlayer(url: smallVideoURL)
|
||||
smallAVPlayer.play()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct TitleView: View {
|
||||
|
||||
@@ -125,7 +125,7 @@ struct ExerciseListView: View {
|
||||
})
|
||||
}
|
||||
}
|
||||
.onChange(of: bridgeModule.currentExerciseInfo.exerciseIndex, perform: { newValue in
|
||||
.onChange(of: bridgeModule.currentExerciseInfo.allSupersetExecerciseIndex, perform: { newValue in
|
||||
if let newCurrentExercise = bridgeModule.currentExerciseInfo.currentExercise {
|
||||
withAnimation {
|
||||
proxy.scrollTo(newCurrentExercise.id, anchor: .top)
|
||||
|
||||
@@ -120,31 +120,11 @@ struct WorkoutDetailView: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
.onChange(of: bridgeModule.currentExerciseInfo.exerciseIndex, perform: { newValue in
|
||||
if let currentExtercise = bridgeModule.currentExerciseInfo.currentExercise {
|
||||
if let videoURL = VideoURLCreator.videoURL(
|
||||
thotStyle: phoneThotStyle,
|
||||
gender: thotGenderOption,
|
||||
defaultVideoURLStr: currentExtercise.exercise.videoURL,
|
||||
exerciseName: currentExtercise.exercise.name,
|
||||
workout: bridgeModule.currentExerciseInfo.workout) {
|
||||
avPlayer = AVPlayer(url: videoURL)
|
||||
avPlayer.play()
|
||||
}
|
||||
}
|
||||
.onChange(of: bridgeModule.currentExerciseInfo.allSupersetExecerciseIndex, perform: { _ in
|
||||
playVideos()
|
||||
})
|
||||
.onChange(of: bridgeModule.isInWorkout, perform: { newValue in
|
||||
if let currentExtercise = bridgeModule.currentExerciseInfo.currentExercise {
|
||||
if let videoURL = VideoURLCreator.videoURL(
|
||||
thotStyle: phoneThotStyle,
|
||||
gender: thotGenderOption,
|
||||
defaultVideoURLStr: currentExtercise.exercise.videoURL,
|
||||
exerciseName: currentExtercise.exercise.name,
|
||||
workout: bridgeModule.currentExerciseInfo.workout) {
|
||||
avPlayer = AVPlayer(url: videoURL)
|
||||
avPlayer.play()
|
||||
}
|
||||
}
|
||||
.onChange(of: bridgeModule.isInWorkout, perform: { _ in
|
||||
playVideos()
|
||||
})
|
||||
.onAppear{
|
||||
if let currentExtercise = bridgeModule.currentExerciseInfo.currentExercise {
|
||||
@@ -165,6 +145,20 @@ struct WorkoutDetailView: View {
|
||||
}
|
||||
}
|
||||
|
||||
func playVideos() {
|
||||
if let currentExtercise = bridgeModule.currentExerciseInfo.currentExercise {
|
||||
if let videoURL = VideoURLCreator.videoURL(
|
||||
thotStyle: phoneThotStyle,
|
||||
gender: thotGenderOption,
|
||||
defaultVideoURLStr: currentExtercise.exercise.videoURL,
|
||||
exerciseName: currentExtercise.exercise.name,
|
||||
workout: bridgeModule.currentExerciseInfo.workout) {
|
||||
avPlayer = AVPlayer(url: videoURL)
|
||||
avPlayer.play()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func startWorkout(workout: Workout) {
|
||||
bridgeModule.completedWorkout = {
|
||||
if let workoutData = createWorkoutData() {
|
||||
|
||||
Reference in New Issue
Block a user