Skip to content

Commit 375f924

Browse files
committed
add volume check
1 parent 9472128 commit 375f924

File tree

5 files changed

+187
-2
lines changed

5 files changed

+187
-2
lines changed

FitCount/Workout/QuickPoseBasicView.swift

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class SessionData: ObservableObject {
1919
}
2020

2121
enum WorkoutState {
22+
case volume
23+
case instructions
2224
case bbox
2325
case exercise
2426
}
@@ -41,7 +43,7 @@ struct QuickPoseBasicView: View {
4143
let exerciseTimer = TimerManager()
4244

4345
@State var isInBBox = false
44-
@State var state = WorkoutState.bbox
46+
@State var state = WorkoutState.volume
4547

4648
@State private var indicatorWidth: CGFloat = 0.0
4749

@@ -84,6 +86,20 @@ struct QuickPoseBasicView: View {
8486
.frame(width: geometry.safeAreaInsets.leading + geometry.size.width + geometry.safeAreaInsets.trailing)
8587
.edgesIgnoringSafeArea(.all)
8688
.overlay() {
89+
if (state == WorkoutState.volume) {
90+
VolumeChangeView().overlay(alignment: .bottom) {
91+
Button (action: {
92+
state = WorkoutState.bbox
93+
VoiceCommands.standInsideBBox.say()
94+
}) {
95+
Text("Continue").foregroundColor(.white)
96+
.padding()
97+
.background(.indigo) // Set background color to the main color
98+
.cornerRadius(8) // Add corner radius for a rounded look
99+
}
100+
}
101+
}
102+
87103
if (state == WorkoutState.bbox) {
88104
BoundingBoxView(isInBBox: isInBBox, indicatorWidth: indicatorWidth)
89105
}
@@ -128,7 +144,7 @@ struct QuickPoseBasicView: View {
128144
.onAppear {
129145
quickPose.start(features: exercise.features, onFrame: { status, image, features, feedback, landmarks in
130146

131-
VoiceCommands.standInsideBBox.say()
147+
132148

133149
let width = geometry.size.width * 0.6
134150
let height = geometry.size.height * 0.8
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
//
2+
// VolumeChangeView.swift
3+
// FitCounter
4+
//
5+
// Created by QuickPose.ai on 02.06.2023.
6+
//
7+
8+
import SwiftUI
9+
import MediaPlayer
10+
import AVFoundation
11+
12+
13+
func setSystemVolume(_ volume: Float) {
14+
let volumeView = MPVolumeView()
15+
let slider = volumeView.subviews.first(where: { $0 is UISlider }) as? UISlider
16+
17+
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.01) {
18+
slider?.setValue(volume, animated: false)
19+
}
20+
}
21+
22+
23+
24+
func getCurrentVolume() -> Float {
25+
let audioSession = AVAudioSession.sharedInstance()
26+
27+
do {
28+
try audioSession.setActive(true)
29+
30+
let volume = audioSession.outputVolume
31+
return volume
32+
} catch {
33+
print("Failed to get current volume: \(error)")
34+
return 0.0
35+
}
36+
}
37+
38+
39+
struct VolumeChangeView: View {
40+
@State private var soundLevel: Float = getCurrentVolume()
41+
42+
init() {
43+
}
44+
45+
var body: some View {
46+
VStack {
47+
Color.white
48+
.ignoresSafeArea()
49+
.overlay(
50+
VStack (spacing: 30){
51+
Text("FiCounter provides real-time voice feedback")
52+
.font(.title)
53+
.multilineTextAlignment(.center)
54+
Text("Please turn on the sound on your device")
55+
.font(.body)
56+
.multilineTextAlignment(.center)
57+
58+
HStack {
59+
Image(systemName: "speaker.wave.1")
60+
.font(.system(size: 30))
61+
.foregroundColor(.indigo)
62+
63+
Slider(value: $soundLevel, in: 0...1, step: 0.01, onEditingChanged: { data in
64+
setSystemVolume(self.soundLevel)
65+
})
66+
.tint(soundLevel < 0.5 ? .red : .green)
67+
68+
Image(systemName: "speaker.wave.3")
69+
.font(.system(size: 30))
70+
.foregroundColor(.indigo)
71+
72+
}
73+
}.frame(width: 300)
74+
)
75+
}
76+
}
77+
}
78+
79+
struct VolumeChangeView_Previews: PreviewProvider {
80+
static var previews: some View {
81+
VolumeChangeView()
82+
}
83+
}

FitCounter by QuickPose.ai.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
920A3EF62A20B14100EC6FC9 /* PagerTabStripView in Frameworks */ = {isa = PBXBuildFile; productRef = 920A3EF52A20B14100EC6FC9 /* PagerTabStripView */; };
1515
924D6E222A264B3600227183 /* JsonWriter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 924D6E212A264B3600227183 /* JsonWriter.swift */; };
1616
924D6E252A289ED700227183 /* AboutView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 924D6E242A289ED700227183 /* AboutView.swift */; };
17+
924D6E282A29F90400227183 /* VolumeChangeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 924D6E272A29F90400227183 /* VolumeChangeView.swift */; };
1718
927261A42A24EF0B00C3B390 /* HistoryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 927261A32A24EF0B00C3B390 /* HistoryView.swift */; };
1819
92C702F92A1BC705002ECC0B /* QuickPoseBasicView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92C702F82A1BC705002ECC0B /* QuickPoseBasicView.swift */; };
1920
92C702FC2A1BC74A002ECC0B /* QuickPoseCamera in Frameworks */ = {isa = PBXBuildFile; productRef = 92C702FB2A1BC74A002ECC0B /* QuickPoseCamera */; };
@@ -56,6 +57,7 @@
5657
920A3EF22A1F801A00EC6FC9 /* Workout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Workout.swift; sourceTree = "<group>"; };
5758
924D6E212A264B3600227183 /* JsonWriter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JsonWriter.swift; sourceTree = "<group>"; };
5859
924D6E242A289ED700227183 /* AboutView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AboutView.swift; sourceTree = "<group>"; };
60+
924D6E272A29F90400227183 /* VolumeChangeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VolumeChangeView.swift; sourceTree = "<group>"; };
5961
927261A32A24EF0B00C3B390 /* HistoryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HistoryView.swift; sourceTree = "<group>"; };
6062
92C702F82A1BC705002ECC0B /* QuickPoseBasicView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuickPoseBasicView.swift; sourceTree = "<group>"; };
6163
92C703032A1D049E002ECC0B /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@@ -113,6 +115,7 @@
113115
920A3EEE2A1F76F800EC6FC9 /* BoundingBoxView.swift */,
114116
920A3EF02A1F7C2300EC6FC9 /* WorkoutResultsView.swift */,
115117
920A3EF22A1F801A00EC6FC9 /* Workout.swift */,
118+
924D6E272A29F90400227183 /* VolumeChangeView.swift */,
116119
);
117120
path = Workout;
118121
sourceTree = "<group>";
@@ -341,6 +344,7 @@
341344
92CACFD12A1B7DD100DA2B40 /* FitCountApp.swift in Sources */,
342345
920A3EEF2A1F76F800EC6FC9 /* BoundingBoxView.swift in Sources */,
343346
920A3EF32A1F801A00EC6FC9 /* Workout.swift in Sources */,
347+
924D6E282A29F90400227183 /* VolumeChangeView.swift in Sources */,
344348
924D6E252A289ED700227183 /* AboutView.swift in Sources */,
345349
920A3EF12A1F7C2300EC6FC9 /* WorkoutResultsView.swift in Sources */,
346350
927261A42A24EF0B00C3B390 /* HistoryView.swift in Sources */,
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "1430"
4+
version = "1.7">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "92CACFCC2A1B7DD100DA2B40"
18+
BuildableName = "FitCounter.app"
19+
BlueprintName = "FitCounter"
20+
ReferencedContainer = "container:FitCounter by QuickPose.ai.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
buildConfiguration = "Debug"
27+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
28+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
shouldUseLaunchSchemeArgsEnv = "YES"
30+
shouldAutocreateTestPlan = "YES">
31+
</TestAction>
32+
<LaunchAction
33+
buildConfiguration = "Debug"
34+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
35+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
36+
launchStyle = "0"
37+
useCustomWorkingDirectory = "NO"
38+
ignoresPersistentStateOnLaunch = "NO"
39+
debugDocumentVersioning = "YES"
40+
debugServiceExtension = "internal"
41+
allowLocationSimulation = "YES">
42+
<BuildableProductRunnable
43+
runnableDebuggingMode = "0">
44+
<BuildableReference
45+
BuildableIdentifier = "primary"
46+
BlueprintIdentifier = "92CACFCC2A1B7DD100DA2B40"
47+
BuildableName = "FitCounter.app"
48+
BlueprintName = "FitCounter"
49+
ReferencedContainer = "container:FitCounter by QuickPose.ai.xcodeproj">
50+
</BuildableReference>
51+
</BuildableProductRunnable>
52+
</LaunchAction>
53+
<ProfileAction
54+
buildConfiguration = "Release"
55+
shouldUseLaunchSchemeArgsEnv = "YES"
56+
savedToolIdentifier = ""
57+
useCustomWorkingDirectory = "NO"
58+
debugDocumentVersioning = "YES">
59+
<BuildableProductRunnable
60+
runnableDebuggingMode = "0">
61+
<BuildableReference
62+
BuildableIdentifier = "primary"
63+
BlueprintIdentifier = "92CACFCC2A1B7DD100DA2B40"
64+
BuildableName = "FitCounter.app"
65+
BlueprintName = "FitCounter"
66+
ReferencedContainer = "container:FitCounter by QuickPose.ai.xcodeproj">
67+
</BuildableReference>
68+
</BuildableProductRunnable>
69+
</ProfileAction>
70+
<AnalyzeAction
71+
buildConfiguration = "Debug">
72+
</AnalyzeAction>
73+
<ArchiveAction
74+
buildConfiguration = "Release"
75+
revealArchiveInOrganizer = "YES">
76+
</ArchiveAction>
77+
</Scheme>

FitCounter by QuickPose.ai.xcodeproj/xcuserdata/denis.xcuserdatad/xcschemes/xcschememanagement.plist

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
<key>orderHint</key>
1010
<integer>0</integer>
1111
</dict>
12+
<key>FitCounter.xcscheme_^#shared#^_</key>
13+
<dict>
14+
<key>orderHint</key>
15+
<integer>0</integer>
16+
</dict>
1217
</dict>
1318
<key>SuppressBuildableAutocreation</key>
1419
<dict>

0 commit comments

Comments
 (0)