質問編集履歴

1

func audioPlayerDidFinishPlayingを加えた修正版です。 最初の投稿で「中略」として記載していなかった箇所も記載しました。

2018/10/03 13:04

投稿

ishiishiyay
ishiishiyay

スコア33

test CHANGED
File without changes
test CHANGED
@@ -132,8 +132,116 @@
132
132
 
133
133
  以下関数でなんとかできないでしょうか?
134
134
 
135
+
136
+
137
+
138
+
139
+ 以下、func audioPlayerDidFinishPlayingを加えた修正版です。
140
+
141
+ 最初の投稿で「中略」として記載していなかった箇所も記載しました。
142
+
143
+
144
+
135
- ```ここに言語を入力
145
+ ```Swift
136
146
 
137
147
  func audioPlayerDidFinishPlaying(_ player: AVAudioPlayer, successfully flag: Bool) {}
138
148
 
139
149
  ```
150
+
151
+
152
+
153
+ ```Swift
154
+
155
+ func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
156
+
157
+ if let cell = collectionView.cellForItem(at: indexPath) as? ImageCollectionViewCell {
158
+
159
+ cell.didSelect(indexPath: indexPath)
160
+
161
+ layer2 = cell.imgImg.layer
162
+
163
+ }
164
+
165
+
166
+
167
+ number = indexPath.row
168
+
169
+
170
+
171
+ //押したら、fiebase上のlistenedがtrueに変わる。
172
+
173
+ let newValuesForProfile = ["listened": true]
174
+
175
+ if messages[indexPath.row].senderId == self.toID {
176
+
177
+ DBProvider.Instance.dbRef.child("Media_Messages").child(messages[indexPath.row].childkey!).updateChildValues(newValuesForProfile)
178
+
179
+ }
180
+
181
+
182
+
183
+ animatePulsatingLayer()//アニメーションの詳細を記述した関数を呼び出す
184
+
185
+
186
+
187
+ do{
188
+
189
+ let message = messages[indexPath.row]
190
+
191
+        let audioUrl = URL(string: message.url!)
192
+
193
+ URLSession.shared.dataTask(with: audioUrl!, completionHandler: { (data, response, error) in
194
+
195
+
196
+
197
+ DispatchQueue.global().async{
198
+
199
+ DispatchQueue.main.async{
200
+
201
+
202
+
203
+ func audioPlayerDidFinishPlaying(_ player: AVAudioPlayer, successfully flag: Bool) {
204
+
205
+
206
+
207
+ do {
208
+
209
+ self.audioPlayer = try AVAudioPlayer(data:data!)
210
+
211
+ self.audioPlayer.delegate = self
212
+
213
+ self.audioPlayer.play()
214
+
215
+ self.myCollectionView.reloadData();
216
+
217
+    }
218
+
219
+ catch{}
220
+
221
+ } //func audioPlayerDidFinishPlaying終了
222
+
223
+ }
224
+
225
+ }
226
+
227
+
228
+
229
+ }).resume()
230
+
231
+
232
+
233
+ } catch {
234
+
235
+ }
236
+
237
+
238
+
239
+ }
240
+
241
+
242
+
243
+
244
+
245
+
246
+
247
+ ```