fix video being out of sync

This commit is contained in:
Trey t
2024-06-13 19:35:25 -05:00
parent 460bd16347
commit 117ebd25a0
4 changed files with 55 additions and 96 deletions

View File

@@ -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)

View File

@@ -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() {