回答編集履歴
2
修正
test
CHANGED
@@ -52,7 +52,13 @@
|
|
52
52
|
|
53
53
|
//停止
|
54
54
|
|
55
|
+
|
56
|
+
|
57
|
+
// 以下を追加
|
58
|
+
|
55
59
|
timer.invalidate()
|
60
|
+
|
61
|
+
|
56
62
|
|
57
63
|
Music01.stop()
|
58
64
|
|
1
修正
test
CHANGED
@@ -3,3 +3,99 @@
|
|
3
3
|
|
4
4
|
|
5
5
|
参考URL: [Swiftでオーディオプレイヤー:UISliderの設置と、曲の再生時間や再生箇所との同期](http://bick.xyz/archives/243)
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
とりあえず動いたので変更部分だけ載せておきます。
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
```swift
|
14
|
+
|
15
|
+
// 以下を追加
|
16
|
+
|
17
|
+
var timer = Timer()
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
//音楽を再生するスイッチを作成
|
22
|
+
|
23
|
+
@IBAction func playSwitch(_ sender: UISwitch) {
|
24
|
+
|
25
|
+
NSLog("\(sender.isOn)")
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
//再生
|
30
|
+
|
31
|
+
if sender.isOn == true {
|
32
|
+
|
33
|
+
Music01.play()
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
//アニメーション開始の処理
|
38
|
+
|
39
|
+
animateStart(target: imgvMusic, key: "Move")
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
// 以下を追加
|
44
|
+
|
45
|
+
timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(updatePlayingTime), userInfo: nil, repeats: true)
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
} else {
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
//停止
|
54
|
+
|
55
|
+
timer.invalidate()
|
56
|
+
|
57
|
+
Music01.stop()
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
//アニメーション停止処理
|
62
|
+
|
63
|
+
Music01.prepareToPlay()
|
64
|
+
|
65
|
+
Music01.currentTime = 0.0
|
66
|
+
|
67
|
+
slMusicSize.value = 0.0
|
68
|
+
|
69
|
+
animateEnd(target: imgvMusic, key: "Move")
|
70
|
+
|
71
|
+
}
|
72
|
+
|
73
|
+
}
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
//再生場所の設定
|
78
|
+
|
79
|
+
@IBAction func musicSizeChange(_ sender: UISlider) {
|
80
|
+
|
81
|
+
Music01.currentTime = TimeInterval(sender.value)
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
// 以下を追加
|
86
|
+
|
87
|
+
self.updatePlayingTime()
|
88
|
+
|
89
|
+
}
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
// 以下を追加
|
94
|
+
|
95
|
+
func updatePlayingTime() {
|
96
|
+
|
97
|
+
slMusicSize.value = Float(Music01.currentTime)
|
98
|
+
|
99
|
+
}
|
100
|
+
|
101
|
+
```
|