質問編集履歴
3
誤字の訂正
test
CHANGED
File without changes
|
test
CHANGED
@@ -274,7 +274,7 @@
|
|
274
274
|
|
275
275
|
を作ってもいいのですが、そうなると、currentPlaybackStateの設定がわからず・・・
|
276
276
|
|
277
|
-
``while player.
|
277
|
+
``while player.PlaybackState == .playing {``
|
278
278
|
|
279
279
|
ではなぜかだめらしく・・・
|
280
280
|
|
2
考察を追記・・・
test
CHANGED
File without changes
|
test
CHANGED
@@ -250,6 +250,38 @@
|
|
250
250
|
|
251
251
|
timerを起動するタイミングがいけないのだろうか・・・。
|
252
252
|
|
253
|
+
|
254
|
+
|
255
|
+
---
|
256
|
+
|
257
|
+
2017.8.18再々更新
|
258
|
+
|
259
|
+
全く別のアプローチとして、currentPlaybackStateがplayingのときのみ、単純なカウンター
|
260
|
+
|
261
|
+
```swift
|
262
|
+
|
263
|
+
func updateElapsedTime() {
|
264
|
+
|
265
|
+
count += 1
|
266
|
+
|
267
|
+
let min = count / 60
|
268
|
+
|
269
|
+
let sec = count % 60
|
270
|
+
|
271
|
+
timeCounter.text = String(format:"%02d:%02d",min, sec)
|
272
|
+
|
273
|
+
```
|
274
|
+
|
275
|
+
を作ってもいいのですが、そうなると、currentPlaybackStateの設定がわからず・・・
|
276
|
+
|
277
|
+
``while player.currentPlaybackState == .playing {``
|
278
|
+
|
279
|
+
ではなぜかだめらしく・・・
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
|
284
|
+
|
253
285
|
###補足情報(言語/FW/ツール等のバージョンなど)
|
254
286
|
|
255
287
|
swift3Xcode8
|
1
新たなエラーを追記
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
swift3 MPMusicPlayerControllerで再生時間を
|
1
|
+
swift3 MPMusicPlayerControllerで再生時間を表示
|
test
CHANGED
@@ -8,23 +8,247 @@
|
|
8
8
|
|
9
9
|
曲のタイトルやアーティスト名などは簡単に表示することができたのですが、
|
10
10
|
|
11
|
-
現在の再生時間を表示することが全くできません。
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
11
|
+
現在の再生時間を**画面に表示**することが全くできません。
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
---
|
16
|
+
|
17
|
+
2017.8.17更新
|
18
|
+
|
19
|
+
timerとcurrentPlaybackTimeを使って
|
20
|
+
|
21
|
+
timerで1秒ごとにUILabelを書き換える動作にしようと思いました。
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
```swift
|
26
|
+
|
27
|
+
var timer = Timer()
|
28
|
+
|
29
|
+
var count: Double = 0.0
|
30
|
+
|
31
|
+
var countInt: Int = 0
|
32
|
+
|
33
|
+
@IBOutlet weak var timeCounter: UILabel!
|
34
|
+
|
35
|
+
@IBOutlet
|
36
|
+
|
37
|
+
//〜省略〜
|
38
|
+
|
39
|
+
func nowPlayingItemChanged(_ notification: NSNotification?) {
|
40
|
+
|
41
|
+
if let mediaItem = player.nowPlayingItem {
|
42
|
+
|
43
|
+
updateSongInformationUI(mediaItem: mediaItem)
|
44
|
+
|
45
|
+
}
|
46
|
+
|
47
|
+
}
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
func updateSongInformationUI(mediaItem: MPMediaItem) {
|
52
|
+
|
53
|
+
//〜省略〜
|
54
|
+
|
55
|
+
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(updateElapsedTime), userInfo: nil, repeats: true)
|
56
|
+
|
57
|
+
}
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
func updateElapsedTime() {
|
62
|
+
|
63
|
+
count = player.currentPlaybackTime
|
64
|
+
|
65
|
+
countInt = Int(count)
|
66
|
+
|
67
|
+
let min = countInt / 60
|
68
|
+
|
69
|
+
let sec = countInt % 60
|
70
|
+
|
71
|
+
timeCounter.text = String(format:"%02d:%02d",min, sec)
|
72
|
+
|
73
|
+
//ここでTimeInterval型->Int型->String型に変更してやっとUILabelに代入する
|
74
|
+
|
75
|
+
}
|
76
|
+
|
77
|
+
```
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
曲が変更された時、それが再生可能な曲であれば、タイマーをスタートさせるという設定にしたつもりです。
|
82
|
+
|
83
|
+
そして、TimeInterval型であるcurrentPlaybackTimeを小数点は切り捨ててInt型にし(そうしないと % 60 が使えなかったため)、最後にUIlabelのtimePathにmm:ssのフォーマットのString型として代入したつもりです。
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
###現在発生しているエラー
|
88
|
+
|
89
|
+
ビルドタイムエラーはなく、実機で起動した際に
|
90
|
+
|
91
|
+
```swift
|
92
|
+
|
93
|
+
testMusic`ViewController.init(coder : NSCoder) -> ViewController?:
|
94
|
+
|
95
|
+
0x1000e760c <+0>: sub sp, sp, #0xc0 ; =0xc0
|
96
|
+
|
97
|
+
0x1000e7610 <+4>: stp x29, x30, [sp, #0xb0]
|
98
|
+
|
99
|
+
0x1000e7614 <+8>: add x29, sp, #0xb0 ; =0xb0
|
100
|
+
|
101
|
+
0x1000e7618 <+12>: adrp x8, 6
|
102
|
+
|
103
|
+
0x1000e761c <+16>: add x8, x8, #0xee8 ; =0xee8
|
104
|
+
|
105
|
+
0x1000e7620 <+20>: stur x0, [x29, #-0x10]
|
106
|
+
|
107
|
+
0x1000e7624 <+24>: stur x1, [x29, #-0x8]
|
108
|
+
|
109
|
+
0x1000e7628 <+28>: stur xzr, [x29, #-0x18]
|
110
|
+
|
111
|
+
0x1000e762c <+32>: ldur x9, [x29, #-0x18]
|
112
|
+
|
113
|
+
-> 0x1000e7630 <+36>: ldr x8, [x8] //thread 1: breakpoint2.4
|
114
|
+
|
115
|
+
//ここで止まってしまう・・・
|
116
|
+
|
117
|
+
0x1000e7634 <+40>: mov x10, x1
|
118
|
+
|
119
|
+
0x1000e7638 <+44>: add x8, x10, x8
|
120
|
+
|
121
|
+
0x1000e763c <+48>: stur x0, [x29, #-0x50]
|
122
|
+
|
123
|
+
0x1000e7640 <+52>: mov x0, x8
|
124
|
+
|
125
|
+
0x1000e7644 <+56>: str x1, [sp, #0x58]
|
126
|
+
|
127
|
+
0x1000e7648 <+60>: mov x1, x9
|
128
|
+
|
129
|
+
0x1000e764c <+64>: str x9, [sp, #0x50]
|
130
|
+
|
131
|
+
0x1000e7650 <+68>: bl 0x1000e968c ; symbol stub for: swift_unknownWeakInit
|
132
|
+
|
133
|
+
0x1000e7654 <+72>: ldr x0, [sp, #0x50]
|
134
|
+
|
135
|
+
0x1000e7658 <+76>: bl 0x1000e9608 ; symbol stub for: objc_release
|
136
|
+
|
137
|
+
0x1000e765c <+80>: adrp x8, 6
|
138
|
+
|
139
|
+
0x1000e7660 <+84>: add x8, x8, #0xef0 ; =0xef0
|
140
|
+
|
141
|
+
0x1000e7664 <+88>: stur xzr, [x29, #-0x20]
|
142
|
+
|
143
|
+
0x1000e7668 <+92>: ldur x9, [x29, #-0x20]
|
144
|
+
|
145
|
+
0x1000e766c <+96>: ldr x8, [x8]
|
146
|
+
|
147
|
+
0x1000e7670 <+100>: ldr x10, [sp, #0x58]
|
148
|
+
|
149
|
+
0x1000e7674 <+104>: add x8, x10, x8
|
150
|
+
|
151
|
+
0x1000e7678 <+108>: mov x0, x8
|
152
|
+
|
153
|
+
0x1000e767c <+112>: mov x1, x9
|
154
|
+
|
155
|
+
0x1000e7680 <+116>: str x9, [sp, #0x48]
|
156
|
+
|
157
|
+
0x1000e7684 <+120>: bl 0x1000e968c ; symbol stub for: swift_unknownWeakInit
|
158
|
+
|
159
|
+
0x1000e7688 <+124>: ldr x0, [sp, #0x48]
|
160
|
+
|
161
|
+
0x1000e768c <+128>: bl 0x1000e9608 ; symbol stub for: objc_release
|
162
|
+
|
163
|
+
0x1000e7690 <+132>: adrp x8, 6
|
164
|
+
|
165
|
+
0x1000e7694 <+136>: add x8, x8, #0xef8 ; =0xef8
|
166
|
+
|
167
|
+
0x1000e7698 <+140>: stur xzr, [x29, #-0x28]
|
168
|
+
|
169
|
+
0x1000e769c <+144>: ldur x9, [x29, #-0x28]
|
170
|
+
|
171
|
+
0x1000e76a0 <+148>: ldr x8, [x8]
|
172
|
+
|
173
|
+
0x1000e76a4 <+152>: ldr x10, [sp, #0x58]
|
174
|
+
|
175
|
+
0x1000e76a8 <+156>: add x8, x10, x8
|
176
|
+
|
177
|
+
0x1000e76ac <+160>: mov x0, x8
|
178
|
+
|
179
|
+
0x1000e76b0 <+164>: mov x1, x9
|
180
|
+
|
181
|
+
0x1000e76b4 <+168>: str x9, [sp, #0x40]
|
182
|
+
|
183
|
+
0x1000e76b8 <+172>: bl 0x1000e968c ; symbol stub for: swift_unknownWeakInit
|
184
|
+
|
185
|
+
0x1000e76bc <+176>: ldr x0, [sp, #0x40]
|
186
|
+
|
187
|
+
0x1000e76c0 <+180>: bl 0x1000e9608 ; symbol stub for: objc_release
|
188
|
+
|
189
|
+
0x1000e76c4 <+184>: adrp x8, 6
|
190
|
+
|
191
|
+
0x1000e76c8 <+188>: add x8, x8, #0xf00 ; =0xf00
|
192
|
+
|
193
|
+
0x1000e76cc <+192>: stur xzr, [x29, #-0x30]
|
194
|
+
|
195
|
+
0x1000e76d0 <+196>: ldur x9, [x29, #-0x30]
|
196
|
+
|
197
|
+
0x1000e76d4 <+200>: ldr x8, [x8]
|
198
|
+
|
199
|
+
0x1000e76d8 <+204>: ldr x10, [sp, #0x58]
|
200
|
+
|
201
|
+
0x1000e76dc <+208>: add x8, x10, x8
|
202
|
+
|
203
|
+
0x1000e76e0 <+212>: mov x0, x8
|
204
|
+
|
205
|
+
0x1000e76e4 <+216>: mov x1, x9
|
206
|
+
|
207
|
+
0x1000e76e8 <+220>: str x9, [sp, #0x38]
|
208
|
+
|
209
|
+
0x1000e76ec <+224>: bl 0x1000e968c ; symbol stub for: swift_unknownWeakInit
|
210
|
+
|
211
|
+
0x1000e76f0 <+228>: ldr x0, [sp, #0x38]
|
212
|
+
|
213
|
+
0x1000e76f4 <+232>: bl 0x1000e9608 ; symbol stub for: objc_release
|
214
|
+
|
215
|
+
0x1000e76f8 <+236>: adrp x8, 6
|
216
|
+
|
217
|
+
0x1000e76fc <+240>: add x8, x8, #0xf08 ; =0xf08
|
218
|
+
|
219
|
+
0x1000e7700 <+244>: stur xzr, [x29, #-0x38]
|
220
|
+
|
221
|
+
0x1000e7704 <+248>: ldur x9, [x29, #-0x38]
|
222
|
+
|
223
|
+
0x1000e7708 <+252>: ldr x8, [x8]
|
224
|
+
|
225
|
+
0x1000e770c <+256>: ldr x10, [sp, #0x58]
|
226
|
+
|
227
|
+
0x1000e7710 <+260>: add x8, x10, x8
|
228
|
+
|
229
|
+
0x1000e7714 <+264>: mov x0, x8
|
230
|
+
|
231
|
+
0x1000e7718 <+268>: mov x1, x9
|
232
|
+
|
233
|
+
0x1000e771c <+272>: str x9, [sp, #0x30]
|
234
|
+
|
235
|
+
0x1000e7720 <+276>: bl 0x1000e968c ; symbol stub for: swift_unknownWeakInit
|
236
|
+
|
237
|
+
0x1000e7724 <+280>: ldr x0, [sp, #0x30]
|
238
|
+
|
239
|
+
0x1000e7728 <+284>: bl 0x1000e9608 ; symbol stub for: objc_release
|
240
|
+
|
241
|
+
0x1000e772c <+288>: bl 0x1000e3e98 ; type metadata accessor for __ObjC.MPMusicPlayerController at ViewController.swift
|
242
|
+
|
243
|
+
//〜省略〜
|
244
|
+
|
245
|
+
```
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
###自分なりの考察
|
250
|
+
|
251
|
+
timerを起動するタイミングがいけないのだろうか・・・。
|
28
252
|
|
29
253
|
###補足情報(言語/FW/ツール等のバージョンなど)
|
30
254
|
|