質問編集履歴
1
func audioPlayerDidFinishPlayingを加えた修正版です。 最初の投稿で「中略」として記載していなかった箇所も記載しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -65,6 +65,60 @@
|
|
65
65
|
|
66
66
|
また、音声の再生が終了したら、アニメーションも止めるようにするにはどうすればいいでしょうか?
|
67
67
|
以下関数でなんとかできないでしょうか?
|
68
|
+
|
69
|
+
|
70
|
+
以下、func audioPlayerDidFinishPlayingを加えた修正版です。
|
71
|
+
最初の投稿で「中略」として記載していなかった箇所も記載しました。
|
72
|
+
|
68
|
-
```
|
73
|
+
```Swift
|
69
74
|
func audioPlayerDidFinishPlaying(_ player: AVAudioPlayer, successfully flag: Bool) {}
|
75
|
+
```
|
76
|
+
|
77
|
+
```Swift
|
78
|
+
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
79
|
+
if let cell = collectionView.cellForItem(at: indexPath) as? ImageCollectionViewCell {
|
80
|
+
cell.didSelect(indexPath: indexPath)
|
81
|
+
layer2 = cell.imgImg.layer
|
82
|
+
}
|
83
|
+
|
84
|
+
number = indexPath.row
|
85
|
+
|
86
|
+
//押したら、fiebase上のlistenedがtrueに変わる。
|
87
|
+
let newValuesForProfile = ["listened": true]
|
88
|
+
if messages[indexPath.row].senderId == self.toID {
|
89
|
+
DBProvider.Instance.dbRef.child("Media_Messages").child(messages[indexPath.row].childkey!).updateChildValues(newValuesForProfile)
|
90
|
+
}
|
91
|
+
|
92
|
+
animatePulsatingLayer()//アニメーションの詳細を記述した関数を呼び出す
|
93
|
+
|
94
|
+
do{
|
95
|
+
let message = messages[indexPath.row]
|
96
|
+
let audioUrl = URL(string: message.url!)
|
97
|
+
URLSession.shared.dataTask(with: audioUrl!, completionHandler: { (data, response, error) in
|
98
|
+
|
99
|
+
DispatchQueue.global().async{
|
100
|
+
DispatchQueue.main.async{
|
101
|
+
|
102
|
+
func audioPlayerDidFinishPlaying(_ player: AVAudioPlayer, successfully flag: Bool) {
|
103
|
+
|
104
|
+
do {
|
105
|
+
self.audioPlayer = try AVAudioPlayer(data:data!)
|
106
|
+
self.audioPlayer.delegate = self
|
107
|
+
self.audioPlayer.play()
|
108
|
+
self.myCollectionView.reloadData();
|
109
|
+
}
|
110
|
+
catch{}
|
111
|
+
} //func audioPlayerDidFinishPlaying終了
|
112
|
+
}
|
113
|
+
}
|
114
|
+
|
115
|
+
}).resume()
|
116
|
+
|
117
|
+
} catch {
|
118
|
+
}
|
119
|
+
|
120
|
+
}
|
121
|
+
|
122
|
+
|
123
|
+
|
70
124
|
```
|