# Audio message length shows 00:00

**URL:** <https://forum.social.plus/t/audio-message-length-shows-00-00/1204>\
**Category:** iOS\
**Created:** [March 19, 2024, 7:40am UTC](https://forum.social.plus/t/audio-message-length-shows-00-00/1204 "2024-03-19T07:40:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vibhorMaheshwari](https://avatars.discourse-cdn.com/v4/letter/v/db5fbb/32.png) [@vibhorMaheshwari](https://forum.social.plus/u/vibhorMaheshwari)\
**Post date:** [March 19, 2024, 7:40am UTC](https://forum.social.plus/t/audio-message-length-shows-00-00/1204/1 "2024-03-19T07:40:39Z")

</div>

Hi, we are using IOS UI kit, and when we send audio message then its displays recording length time is 00:00 always,  
can you please tell us how to fix this.

Screenshot below:

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/amity/original/1X/a71a287cb24afa811648b5f76d30b37febc1b5b0.png)

---

<div class="post-metadata">

**Author:** ![SocialPlus\_Support](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.social.plus/socialplus_support/32/798_2.png) [@SocialPlus\_Support](https://forum.social.plus/u/SocialPlus_Support)\
**Post date:** [March 19, 2024, 8:01am UTC](https://forum.social.plus/t/audio-message-length-shows-00-00/1204/2 "2024-03-19T08:01:56Z")

</div>

@vibhorMaheshwari From your issue, could I request the full code that you’ve implemented for review?

---

<div class="post-metadata">

**Author:** ![vibhorMaheshwari](https://avatars.discourse-cdn.com/v4/letter/v/db5fbb/32.png) [@vibhorMaheshwari](https://forum.social.plus/u/vibhorMaheshwari)\
**Post date:** [March 19, 2024, 9:35am UTC](https://forum.social.plus/t/audio-message-length-shows-00-00/1204/3 "2024-03-19T09:35:06Z")

</div>

@SocialPlus_Support

Code Snap:

```auto
import UIKit
import AmitySDK

final class AmityMessageAudioTableViewCell: AmityMessageTableViewCell {
    
    @IBOutlet private var durationLabel: UILabel!
    @IBOutlet private var actionImageView: UIImageView!
    @IBOutlet private var activityIndicatorView: UIActivityIndicatorView!
    
    override func awakeFromNib() {
        super.awakeFromNib()
        setupView()
    }
    
    override func prepareForReuse() {
        super.prepareForReuse()
        durationLabel.text = "0:00"
        actionImageView.image = AmityIconSet.Chat.iconPlay
    }
    
    func setupView() {
        durationLabel.text = "0:00"
        durationLabel.font = AmityFontSet.body
        durationLabel.textAlignment = .right
        actionImageView.image = AmityIconSet.Chat.iconPlay
        
        activityIndicatorView.hidesWhenStopped = true
        
    }
    
    override func display(message: AmityMessageModel) {
        
        if !message.isDeleted {
            if message.isOwner {
                durationLabel.textColor = AmityColorSet.baseInverse
                actionImageView.tintColor = AmityColorSet.baseInverse
                activityIndicatorView.style = .medium
                switch message.syncState {
                case .syncing:
                    durationLabel.alpha = 0
                    activityIndicatorView.startAnimating()
                case .synced, .default, .error:
                    durationLabel.alpha = 1
                    activityIndicatorView.stopAnimating()
                @unknown default:
                    break
                }
            } else {
                durationLabel.textColor = AmityColorSet.base
                actionImageView.tintColor = AmityColorSet.base
                activityIndicatorView.style = .medium
            }
            
            if AmityAudioPlayer.shared.isPlaying(), AmityAudioPlayer.shared.fileName == message.messageId {
                actionImageView.image = AmityIconSet.Chat.iconPause
            } else {
                actionImageView.image = AmityIconSet.Chat.iconPlay
            }
        }
        super.display(message: message)
    }
    
    override class func height(for message: AmityMessageModel, boundingWidth: CGFloat) -> CGFloat {
        let displaynameHeight: CGFloat = message.isOwner ? 0 : 22
        if message.isDeleted {
            return AmityMessageTableViewCell.deletedMessageCellHeight + displaynameHeight
        }
        return 90 + displaynameHeight
    }
    
}

extension AmityMessageAudioTableViewCell {
    @IBAction func playTap(_ sender: UIButton) {
        if !message.isDeleted && message.syncState == .synced {
            sender.isEnabled = false
            AmityUIKitManagerInternal.shared.messageMediaService.download(for: message.object) { [weak self] in
                self?.durationLabel.alpha = 0
                self?.activityIndicatorView.startAnimating()
            } completion: { [weak self] (result) in
                guard let strongSelf = self else { return }
                switch result {
                case .success(let url):
                    AmityAudioPlayer.shared.delegate = self
                    AmityAudioPlayer.shared.fileName = strongSelf.message.messageId
                    AmityAudioPlayer.shared.path = url
                    AmityAudioPlayer.shared.play()
                    sender.isEnabled = true
                    strongSelf.activityIndicatorView.stopAnimating()
                    strongSelf.durationLabel.alpha = 1
                case .failure(let error):
                    Log.add(error.localizedDescription)
                }
            }
        }
    }
}

extension AmityMessageAudioTableViewCell: AmityAudioPlayerDelegate {
    func playing() {
        actionImageView.image = AmityIconSet.Chat.iconPause
        delegate?.performEvent(self, events: .audioPlaying)
    }
    
    func stopPlaying() {
        actionImageView.image = AmityIconSet.Chat.iconPlay
        durationLabel.text = "0:00"
    }
    
    func finishPlaying() {
        actionImageView.image = AmityIconSet.Chat.iconPlay
        durationLabel.text = "0:00"
    }
    
    func displayDuration(_ duration: String) {
        durationLabel.text = duration
    }
}

```

---

<div class="post-metadata">

**Author:** ![SocialPlus\_Support](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.social.plus/socialplus_support/32/798_2.png) [@SocialPlus\_Support](https://forum.social.plus/u/SocialPlus_Support)\
**Post date:** [March 19, 2024, 10:30am UTC](https://forum.social.plus/t/audio-message-length-shows-00-00/1204/4 "2024-03-19T10:30:37Z")

</div>

@vibhorMaheshwari We have checked with the relevant team and found that, by design, the SDK does not provide the duration of audio files. However, there is a workaround to display the audio duration:

1. After completing the audio recording, save the audio duration in the message metadata.
2. To display the audio duration, extract this information from the message metadata.

---

<div class="post-metadata">

**Author:** ![vibhorMaheshwari](https://avatars.discourse-cdn.com/v4/letter/v/db5fbb/32.png) [@vibhorMaheshwari](https://forum.social.plus/u/vibhorMaheshwari)\
**Post date:** [March 20, 2024, 7:02am UTC](https://forum.social.plus/t/audio-message-length-shows-00-00/1204/5 "2024-03-20T07:02:59Z")

</div>

@SocialPlus_Support  
Thanks for your support, we have fixed this by using metadata.
