Chat Audio Preview
Overview
The LMChatAudioPreview
is used to display and control audio previews within chat messages. It extends the functionality of LMChatVoiceNotePreview by adding a thumbnail image, title, and more detailed UI elements for audio playback.
UI Components
containerView
: AnLMView
that serves as the main container.thumbnailImage
: AnLMImageView
displaying the audio thumbnail.headphoneContainerView
: AnLMView
containing the headphone icon and duration label.headphoneImage
: AnLMImageView
showing an audio icon.durationLbl
: AnLMLabel
displaying the current playback time or total duration.playPauseButton
: AnLMImageView
that toggles between play and pause.slider
: AUISlider
for seeking through the audio.titleLabel
: AnLMLabel
showing the audio file name.
Methods
didTapPlayPauseButton()
: Handles play/pause button taps.didSeekPlayer(slider:event:)
: Manages slider value changes for seeking.configure(with:delegate:index:)
: Configures the view with audio 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
CustomChatAudioPreview.swift
class CustomChatAudioPreview: LMChatAudioPreview {
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 audio preview class if needed
LMUIComponents.shared.audioPreview = CustomChatAudioPreview.self
// ...
return true
}