This commit is contained in:
nielsandriesse 2020-10-02 11:04:37 +10:00
parent f18a4a60a1
commit cc424a9a38
3 changed files with 10 additions and 7 deletions

View File

@ -3,6 +3,7 @@ import Accelerate
@objc(LKVoiceMessageView2)
final class VoiceMessageView2 : UIView {
private let voiceMessage: TSAttachment
private let isOutgoing: Bool
private var isAnimating = false
private var volumeSamples: [Float] = [] { didSet { updateShapeLayers() } }
private var progress: CGFloat = 0
@ -30,7 +31,7 @@ final class VoiceMessageView2 : UIView {
private lazy var foregroundShapeLayer: CAShapeLayer = {
let result = CAShapeLayer()
result.fillColor = isLightMode ? UIColor.white.cgColor : Colors.accent.cgColor
result.fillColor = (isLightMode && isOutgoing) ? UIColor.white.cgColor : Colors.accent.cgColor
return result
}()
@ -41,9 +42,10 @@ final class VoiceMessageView2 : UIView {
@objc public static let contentHeight: CGFloat = 32
// MARK: Initialization
@objc(initWithVoiceMessage:)
init(voiceMessage: TSAttachment) {
@objc(initWithVoiceMessage:isOutgoing:)
init(voiceMessage: TSAttachment, isOutgoing: Bool) {
self.voiceMessage = voiceMessage
self.isOutgoing = isOutgoing
super.init(frame: CGRect.zero)
initialize()
}

View File

@ -39,9 +39,9 @@ enum AudioUtilities {
return Promise(error: Error.noAudioTrack)
}
let (promise, seal) = Promise<FileInfo>.pending()
asset.loadValuesAsynchronously(forKeys: [ "duration" ]) {
asset.loadValuesAsynchronously(forKeys: [ #keyPath(AVAsset.duration) ]) {
var nsError: NSError?
let status = asset.statusOfValue(forKey: "duration", error: &nsError)
let status = asset.statusOfValue(forKey: #keyPath(AVAsset.duration), error: &nsError)
switch status {
case .loaded:
guard let formatDescriptions = track.formatDescriptions as? [CMAudioFormatDescription],

View File

@ -839,8 +839,9 @@ NS_ASSUME_NONNULL_BEGIN
OWSAssertDebug(attachment);
OWSAssertDebug([attachment isAudio]);
LKVoiceMessageView2 *voiceMessageView = [[LKVoiceMessageView2 alloc] initWithVoiceMessage:attachment];
voiceMessageView.duration = (int)self.viewItem.audioDurationSeconds;
LKVoiceMessageView2 *voiceMessageView = [[LKVoiceMessageView2 alloc] initWithVoiceMessage:attachment isOutgoing:self.isOutgoing];
[voiceMessageView setDuration:(int)self.viewItem.audioDurationSeconds];
[voiceMessageView updateForProgress:self.viewItem.audioProgressSeconds / self.viewItem.audioDurationSeconds];
self.viewItem.lastAudioMessageView = voiceMessageView;