Skip to main content

Audio Content View

Overview

The LMChatAudioContentView is a subclass of LMChatMessageContentView responsible for displaying audio content within chat messages. It supports both audio files and voice notes, providing a customizable interface for audio playback and management.

Functionality

Protocols Implemented

UI Components

  • audioPreviewContainerStackView: A vertical LMStackView that contains the audio preview elements.
  • cancelRetryContainerStackView: A stack view for cancel and retry buttons (inherited from superclass).
  • loaderView: A view to display loading state (inherited from superclass).
  • retryView: A view to display retry option for failed messages (inherited from superclass).

Properties

  • onShowMoreCallback: An optional closure called when the user taps to show more audio attachments.
  • audioDelegate: A weak reference to an object conforming to LMChatAudioProtocol.

Methods

  • setDataView(_:index:): Populates the view with data from a LMChatMessageCell.ContentModel.
  • attachmentView(_:delegate:index:): Configures the view based on the type of audio attachment.
  • audioPreview(_:delegate:index:): Sets up the preview for audio file attachments.
  • voiceNotePreview(_:delegate:index:): Sets up the preview for voice note attachments.
  • createAudioPreview(with:delegate:index:): Creates a voice note preview view.
  • prepareToResuse(): Prepares the view for reuse in a table or collection view.
  • resetAudio(): Resets the audio playback state of all audio previews.
  • seekSlider(to:url:): Updates the seeker position for a specific audio URL.

Customization

CustomAudioContentView.swift
class CustomAudioContentView: LMChatAudioContentView {
override func setupViews() {
super.setupViews()
// Add custom views or modify existing ones
}

override func attachmentView(_ data: LMChatMessageCell.ContentModel, delegate: LMChatAudioProtocol?, index: IndexPath) {
super.attachmentView(data, delegate: delegate, index: index)
// Customize attachment view behavior
}
}
AppDelegate.swift
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
LMUIComponents.shared.audioContentView = CustomAudioContentView.self
// ...
return true
}