Basic Usage Examples
Welcome to the practical examples section! Here you'll find real-world implementations showing how to use audio-channel-queue
in your applications.
🎮 Interactive Demo​
The best way to understand the library is to try our interactive demo:
👉 Live Demo
This demo includes:
- Queue Management - Add, remove, and prioritize audio
- Pause & Resume - With smooth fade effects
- Volume Control - Per-channel and master volume
- Real-time Progress - Visual feedback and progress tracking
🚀 Quick Start Example​
Here's a minimal example to get you started:
import { queueAudio, pauseChannel, resumeChannel, setChannelVolume } from 'audio-channel-queue';
// Queue some audio files
queueAudio('sounds/background-music.mp3', 0);
queueAudio('sounds/sound-effect.mp3', 1);
// Control playback
pauseChannel(0); // Pause background music
resumeChannel(0); // Resume background music
// Adjust volumes
setChannelVolume(0, 0.5); // 50% volume for channel 0
setChannelVolume(1, 0.8); // 80% volume for channel 1
📋 Common Use Cases​
Game Audio System​
// Background music on channel 0
queueAudio('music/level1-theme.mp3', 0, { loop: true });
// Sound effects on channel 1
queueAudio('sounds/jump.mp3', 1);
queueAudio('sounds/collect-coin.mp3', 1);
// UI sounds on channel 2
queueAudio('sounds/button-click.mp3', 2);
Web Application​
// Notification sounds
queueAudio('notifications/message.mp3', 0);
queueAudio('notifications/alert.mp3', 0);
// Background ambiance
queueAudio('ambient/office-sounds.mp3', 1, {
loop: true,
gain: 0.3
});
Interactive Media Player​
// Main audio content
queueAudio('podcast/episode-1.mp3', 0);
// Pause with smooth fade
await setChannelVolume(0, 0, 1000, 'ease-out');
pauseChannel(0);
// Resume with fade-in
resumeChannel(0);
await setChannelVolume(0, 1, 1000, 'ease-in');
🎯 Try the Live Examples​
Ready to see these concepts in action?
👉 Explore Interactive Examples
The live demo includes all the code examples above plus advanced features like:
- Multiple fade curve types (linear, ease-in, ease-out, ease-in-out)
- Real-time volume control with visual feedback
- Multi-channel audio management
- Progress tracking and visualization
📚 Next Steps​
- API Reference - Complete function documentation
- Core Concepts - Understanding channels and queues
- Advanced Features - Power user techniques
💡 Need Help?​
Having trouble? Check out our: