partial development in add audio message support

This commit is contained in:
Iosif Moldovan
2018-10-03 12:19:33 +03:00
parent 46d9f1c4d9
commit 515b98ce45
25 changed files with 643 additions and 21 deletions
@@ -26,6 +26,7 @@ import UIKit
import MapKit
import MessageKit
import MessageInputBar
import AVFoundation
final class BasicExampleViewController: ChatViewController {
@@ -96,7 +97,38 @@ extension BasicExampleViewController: MessagesDisplayDelegate {
return LocationMessageSnapshotOptions(showsBuildings: true, showsPointsOfInterest: true, span: MKCoordinateSpan(latitudeDelta: 10, longitudeDelta: 10))
}
// MARK: - Audio Messages
func audioTintColor(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> UIColor {
return self.isFromCurrentSender(message: message) ? .white : UIColor(red: 15/255, green: 135/255, blue: 255/255, alpha: 1.0)
}
// func configureAudioCell(_ audioCell: AudioMessageCell, for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) {
// // if audio player is in pause or currently playing configure the cell accordingly
// guard let player = audioPlayer else {
// return
// }
// switch message.kind {
// case .audio(let item):
// if item.url.absoluteString == player.url?.absoluteString { // make sure you configure the right cell
// let totalDuration = self.audioPlayer?.duration ?? 0.0
// let currentTime = self.audioPlayer?.currentTime ?? 0.0
// let percent = (totalDuration != 0) ? (Float(currentTime/totalDuration)) : 0.0
// audioCell.updateProgress(percent: percent, duration: currentTime)
// // restart audio timer since the cell was reconfigured
// if self.audioTimer?.isValid == true {
// self.audioTimer?.invalidate()
// print("Restart timer with new cell: \(audioCell)")
// self.audioTimer = Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(ChatViewController.didFireAudioTimer(_:)), userInfo: audioCell, repeats: true)
// } else {
// audioCell.pasue() // if the audio timer is invalidate it means the cell is in pause
// }
// }
// default: break
// }
// }
}
// MARK: - MessagesLayoutDelegate