Skip to main content

Chat Voice Note Preview

Overview

The LMChatVoiceNotePreview is used to display and control voice note previews within chat messages. It provides play/pause functionality, a seek slider, and duration display for audio messages.

Functionality

Protocols

LMChatAudioProtocol

  • didTapPlayPauseButton(for url: String, index: IndexPath): triggered when audio is been played or paused
  • didSeekTo(_ position: Float, _ url: String, index: IndexPath): triggered when user seeks the seeker
  • pauseAudioPlayer(): triggered to pause the audio player

UI Components

  • containerView: An LMView that serves as the main container.
  • playPauseButton: An LMImageView that toggles between play and pause.
  • slider: A UISlider for seeking through the audio.
  • img: An LMImageView displaying a microphone icon.
  • durationLbl: An LMLabel showing the current playback time or total duration.

Methods

  • didTapPlayPauseButton(): Handles play/pause button taps.
  • didSeekPlayer(slider:event:): Manages slider value changes for seeking.
  • configure(with:delegate:index:): Configures the view with voice note data.
  • updateSeekerValue(with:for:): Updates the slider position during playback.
  • resetView(): Resets the view to its initial state.
  • convertSecondsToFormattedTime(seconds:): Converts seconds to a formatted time string.

Customization

CustomChatVoiceNotePreview.swift
class CustomChatVoiceNotePreview: LMChatVoiceNotePreview {
override func setupViews() {
super.setupViews()
// Add custom view setup here
}

override func configure(with data: LMChatAudioContentModel, delegate: LMChatAudioProtocol?, index: IndexPath) {
super.configure(with: data, delegate: delegate, index: index)
// Add custom configuration logic here
}
}
AppDelegate.swift
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
// Register custom voice note preview class if needed
LMUIComponents.shared.voiceNotePreview = CustomChatVoiceNotePreview.self
// ...
return true
}