From 234152a2f90fe43727a24d331fdf5ef6a386ce9f Mon Sep 17 00:00:00 2001 From: Christophe Deschamps Date: Wed, 19 Jan 2022 18:27:12 +0100 Subject: [PATCH] Fix duration display on mkv voice memos --- Classes/LinphoneUI/UIChatBubblePhotoCell.m | 10 +--------- Classes/LinphoneUI/UIChatBubbleTextCell.m | 13 +++++++------ 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/Classes/LinphoneUI/UIChatBubblePhotoCell.m b/Classes/LinphoneUI/UIChatBubblePhotoCell.m index ccf47d7aa..19d865875 100644 --- a/Classes/LinphoneUI/UIChatBubblePhotoCell.m +++ b/Classes/LinphoneUI/UIChatBubblePhotoCell.m @@ -184,7 +184,7 @@ _voiceRecordingFile = [NSString stringWithUTF8String:[VFSUtil vfsEnabledWithGroupName:kLinphoneMsgNotificationAppGroupId] ? linphone_content_get_plain_file_path(voiceContent) : linphone_content_get_file_path(voiceContent)]; if ([VFSUtil vfsEnabledWithGroupName:kLinphoneMsgNotificationAppGroupId]) [encrptedFilePaths setValue:_voiceRecordingFile forKey:[NSString stringWithUTF8String:linphone_content_get_name(voiceContent)]]; - [self setVoiceMessageDuration]; + _vrTimerLabel.text = [self formattedDuration:linphone_content_get_file_duration(voiceContent)/1000]; _vrWaveMaskPlayback.frame = CGRectZero; _vrWaveMaskPlayback.backgroundColor = linphone_chat_message_is_outgoing(self.message) ? UIColor.orangeColor : UIColor.grayColor; } @@ -755,14 +755,6 @@ // Voice messages -static AVAudioPlayer* utilityPlayer; - --(void) setVoiceMessageDuration { - NSError *error = nil; - AVAudioPlayer* utilityPlayer = [[AVAudioPlayer alloc]initWithContentsOfURL:[NSURL URLWithString:_voiceRecordingFile] error:&error]; // Workaround as opening multiple linphone_players at the same time can cause crash (here for example layout refreshed whilst a voice memo is playing - _vrTimerLabel.text = [self formattedDuration:utilityPlayer.duration]; - utilityPlayer = nil; -} -(void) voicePlayTimerUpdate { CGRect r = _vrWaveMaskPlayback.frame; diff --git a/Classes/LinphoneUI/UIChatBubbleTextCell.m b/Classes/LinphoneUI/UIChatBubbleTextCell.m index 4038ac799..6d8d01083 100644 --- a/Classes/LinphoneUI/UIChatBubbleTextCell.m +++ b/Classes/LinphoneUI/UIChatBubbleTextCell.m @@ -385,15 +385,16 @@ static const CGFloat REPLY_OR_FORWARD_TAG_HEIGHT = 18; } -+(NSString *)formattedDuration:(long)valueMs { - return [NSString stringWithFormat:@"%02ld:%02ld", valueMs/ 60, (valueMs % 60) ]; ++(NSString *)formattedDuration:(long)valueSec { + return [NSString stringWithFormat:@"%02ld:%02ld", valueSec/ 60, (valueSec % 60) ]; } +(NSString *) recordingDuration:(NSString *) _voiceRecordingFile{ - NSError *error = nil; - AVAudioPlayer* utilityPlayer = [[AVAudioPlayer alloc]initWithContentsOfURL:[NSURL URLWithString:_voiceRecordingFile] error:&error]; // Workaround as opening multiple linphone_players at the same time can cause crash (here for example layout refreshed whilst a voice memo is playing - return [self formattedDuration:utilityPlayer.duration]; - utilityPlayer = nil; + LinphonePlayer *p = linphone_core_create_local_player(LC, nil, nil, nil); + linphone_player_open(p, _voiceRecordingFile.UTF8String); + NSString *result = [self formattedDuration:linphone_player_get_duration(p)]; + linphone_player_close(p); + return result; } + (UIImage *)getImageFromFileName:(NSString *)fileName forReplyBubble:(BOOL)forReplyBubbble {