Skip to main content
The CometChatAudioBubble component is a sophisticated audio message display component that renders audio messages with real-time waveform visualization and playback controls. It serves as the primary content renderer for audio-based messages in the CometChat Angular UIKit, handling everything from single audio display to complex multi-audio layouts with expand/collapse behavior.

Overview

The Audio Bubble component renders audio messages with waveform visualization and playback controls while maintaining visual consistency with the design system and ensuring full accessibility:
  • Message Object Processing: Extracts attachments and metadata from CometChat.MediaMessage objects
  • Single Audio Display: Waveform visualization with play/pause button and time display
  • Real-time Waveform: Visual representation of audio amplitude with seek support via WaveSurfer
  • Playback Controls: Play/pause with single audio player policy (only one audio plays at a time)
  • Time Display: Current time / duration in M:SS format
  • Download with Progress: Circular progress indicator with cancellation support
  • Caption Support: Renders captions using TextMessageBubbleComponent
  • Dual Styling: Supports sender (outgoing) and receiver (incoming) visual variants
  • Accessibility: Full keyboard navigation and screen reader support
Live Preview — Default audio bubble preview. Open in Storybook ↗

Basic Usage

Simple Audio Message

Incoming vs Outgoing Messages

With Event Handlers

Properties

Events

Advanced Usage

Single Audio Message

The component displays single audio messages with waveform visualization and playback controls:
Single Audio Features:
  • Play/pause button on the left
  • Real-time waveform visualization with seek support
  • Current time / duration display (M:SS format)
  • Download button on the right
  • Fixed width of 240px for consistent layout

Audios with Captions

The component automatically renders captions using the TextMessageBubbleComponent:
Caption Features:
  • Displays below the audio(s)
  • Supports rich text formatting (bold, italic, etc.)
  • Supports @mentions with click events
  • Supports URLs with click events
  • Supports read more/less for long captions
  • Inherits alignment from parent bubble

Waveform Visualization

The component uses an embedded WaveSurfer library for real-time waveform visualization:
Waveform Features:
  • Real-time audio amplitude visualization
  • Click to seek to any position
  • Drag to seek with real-time updates
  • Different colors for played vs unplayed portions
  • Sender variant: white progress, neutral-500 wave color
  • Receiver variant: primary color progress, extended-primary-300 wave color
  • Fixed width of 140px within the audio bubble
  • Height of 16px for waveform bars

Download with Progress

The component provides download functionality with a circular progress indicator:
Download Features:
  • Circular progress indicator showing completion percentage (0-100%)
  • Cancel button in the center of the progress circle
  • Automatic file download with original filename on completion
  • Error handling with event emission
  • Sender variant: white download icon and progress
  • Receiver variant: primary color download icon and progress

Single Audio Player Policy

The component implements a single audio player policy - only one audio can play at a time across all audio bubbles:
Single Player Policy Features:
  • Only one audio plays at a time across all audio bubbles
  • Starting a new audio automatically pauses any currently playing audio
  • Global singleton tracks the currently playing audio
  • Automatic cleanup on component destruction

Time Display

The component displays current playback time and total duration:
Time Display Features:
  • Format: “M:SS / M:SS” (current / total)
  • Updates continuously during playback
  • Updates immediately on seek via waveform
  • Sender variant: white text color
  • Receiver variant: neutral-600 text color

Customization

Styling with CSS Variables

The Audio Bubble component uses CSS variables exclusively for easy customization:

Available CSS Variables

Custom Color Schemes

Custom Play Button Styling

Custom Expand Indicator Styling

Custom Download Progress Styling

Accessibility

The Audio Bubble component is fully accessible and follows WCAG 2.1 Level AA guidelines.

WCAG 2.1 Compliance

The component meets the following WCAG 2.1 Level AA success criteria:
  • 1.1.1 Non-text Content (Level A): All controls have descriptive ARIA labels
  • 1.3.1 Info and Relationships (Level A): Proper semantic structure with buttons
  • 2.1.1 Keyboard (Level A): All functionality available via keyboard
  • 2.4.7 Focus Visible (Level AA): Clear focus indicators on all interactive elements
  • 4.1.2 Name, Role, Value (Level A): All elements have accessible names and roles

Keyboard Support

ARIA Attributes

The component automatically applies appropriate ARIA attributes:

Screen Reader Behavior

Screen readers announce the audio bubble with:
  1. Play button: “Button, Play audio”
  2. Pause button: “Button, Pause audio”
  3. Download button: “Button, Download audio”
  4. Expand indicator: “Button, Show 3 more, collapsed”
  5. Collapse button: “Button, Show less, expanded”
  6. State changes: Announces playback state changes

Accessibility Best Practices

The component automatically handles all accessibility requirements. No additional ARIA attributes or keyboard handling is needed.
When handling playStateChange events, ensure your custom actions maintain accessibility by managing focus appropriately.
All interactive elements (play/pause, download, expand/collapse, waveform) are keyboard accessible and have visible focus indicators.

Best Practices

Always provide the complete CometChat.MediaMessage object to ensure all features (attachments, captions, metadata) work correctly.
The component expects audio attachments with valid URLs. Ensure your message objects have properly formatted attachment data.
Use the alignment property to distinguish between incoming and outgoing messages for proper visual styling.
Handle playStateChange events to track analytics or perform custom actions when audio playback state changes.
The component does NOT open a modal or fullscreen view. Expansion happens inline within the message bubble.
The component handles missing or invalid data gracefully, displaying error states without breaking the UI.
The single audio player policy ensures a good user experience - only one audio plays at a time across all audio bubbles.
  • CometChatTextBubble: Used for rendering captions in audio messages
  • CometChatFileBubble: Displays file messages with download functionality
  • CometChatImageBubble: Displays image messages with grid layouts and gallery
  • CometChatVideoBubble: Displays video messages with thumbnails and player
  • CometChatMessageBubble: Uses Audio Bubble as the content view for audio messages
  • CometChatMessageList: Displays lists of messages including audio bubbles

Technical Details

  • Standalone Component: Can be imported and used independently
  • Change Detection: Uses OnPush change detection strategy for optimal performance
  • Dependencies:
    • Angular CommonModule
    • CometChat SDK for message types
    • TranslatePipe for localization
    • CometChatTextBubbleComponent for captions
    • Embedded WaveSurfer library for waveform visualization
  • Bundle Size: Minimal footprint (~15KB including WaveSurfer)
  • BEM CSS: Follows Block Element Modifier naming convention
  • Accessibility: WCAG 2.1 Level AA compliant

Performance Considerations

Optimization Strategies

Change Detection:
  • Uses OnPush strategy to minimize unnecessary re-renders
  • Only updates when inputs change or events are emitted
WaveSurfer Initialization:
  • WaveSurfer instances are created lazily (only when visible)
  • Instances are properly destroyed on component destruction
  • Audio decoding happens asynchronously to avoid blocking UI
Single Audio Player Policy:
  • Global singleton ensures only one audio plays at a time
  • Reduces memory usage and improves performance
  • Automatic cleanup when components are destroyed
Download Progress:
  • Uses ReadableStream for efficient progress tracking
  • Supports cancellation via AbortController
  • Progress updates are throttled to avoid excessive re-renders

Best Practices for Performance

The component uses OnPush change detection. Ensure message objects are immutable for optimal performance.
WaveSurfer instances are created lazily. Only visible audio attachments have active waveform visualizations.
Avoid frequently changing the message input. Each change triggers re-processing of attachments and WaveSurfer re-initialization.
The embedded WaveSurfer library is optimized for the audio bubble use case with minimal configuration.
For troubleshooting tips, see the Troubleshooting Guide.