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 pauseddidSeekTo(_ position: Float, _ url: String, index: IndexPath)
: triggered when user seeks the seekerpauseAudioPlayer()
: triggered to pause the audio player
UI Components
containerView
: AnLMView
that serves as the main container.playPauseButton
: AnLMImageView
that toggles between play and pause.slider
: AUISlider
for seeking through the audio.img
: AnLMImageView
displaying a microphone icon.durationLbl
: AnLMLabel
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
}