Remu Audio
A powerful Rust asynchronous audio playback library with support for local file playback and network streaming.
English | 简体中文
✨ Features
- 🎵 Multiple Format Support - Supports common audio formats including MP3, WAV, FLAC, OGG, and more
- 🌐 Network Streaming - Load and play audio streams from URLs
- ⚡ Async Loading - Tokio-based asynchronous downloading and playback
- 🎛️ Full Control - Play, pause, seek, volume control, and more
- 📡 Event-Driven - Rich event callback system for playback events
- 🔧 Flexible Extension - Support for custom Readers and Sources
📦 Installation
Add the dependency to your Cargo.toml:
[]
= "0.1.0"
🚀 Quick Start
Basic Example
use ;
use PlayerEvent;
use Result;
async
Network Streaming
// Load audio from URL
player.load_url.await?;
player.play;
Playback Control
// Pause
player.pause;
// Resume playback
player.play;
// Seek to position (20 seconds)
player.seek?;
// Set volume (0.0 - 1.0)
player.set_volume;
// Get playback state
let is_paused = player.paused;
let position = player.position;
let duration = player.duration;
let volume = player.volume;
📚 API Documentation
Player
The main player class providing audio loading and playback functionality.
Methods
new()- Create a new player instanceload_file(path: &str)- Load a local audio fileload_url(url: &str)- Load audio from a URLload_reader<R>(reader: R)- Load from a custom Readerload_source(source: impl Source)- Load from a Sourceset_callback<F>(callback: F)- Set playback event callbackset_loader_callback<F>(callback: F)- Set loader event callbackstop()- Stop playback and clear stateended()- Check if playback has ended
PlaybackControl Trait
Provides playback control interface, implemented by Player and PlayerControl.
Methods
play()- Start/resume playbackpause()- Pause playbackseek(position: Duration)- Seek to a specific positionset_volume(volume: f32)- Set volume (0.0 - 1.0)paused()- Get pause stateposition()- Get current playback positionduration()- Get total durationvolume()- Get current volume
PlayerEvent
Player event enumeration used for event callbacks.
Event Types
Play- Playback started or resumed from pausePause- Playback pausedPlaying- Currently playing (data sufficient)Waiting- Buffering/waiting for dataEnded- Playback endedEmptied- Playback content clearedDurationChange- Duration changedVolumeChange- Volume changedSeeking- Seek operation startedSeeked- Seek operation completedLoadStart- Loading startedLoadedData- Data loadedLoadedMetadata- Metadata loadedError { message: String }- An error occurred
LoaderEvent
Loader event enumeration for monitoring download status.
Event Types
Completed- Download completedAborted- Download aborted
🎯 Use Cases
Use Case 1: Music Player
let mut player = new?;
// Set up comprehensive event listeners
player.set_callback;
player.load_file.await?;
player.play;
Use Case 2: Streaming Media Player
let mut player = new?;
// Monitor download progress
player.set_loader_callback;
// Load network audio
player.load_url.await?;
player.play;
Use Case 3: Shared Controller
let mut player = new?;
let control = player.control;
// Control playback from another thread
spawn;
🔧 Dependencies
rodio- Audio playback coresymphonia- Audio decodingcpal- Cross-platform audio I/Otokio- Async runtimereqwest- HTTP clientanyhow- Error handling
📝 Examples
The project includes complete example code demonstrating various use cases:
The example file is located at examples/test_playback.rs and includes:
- Local file playback
- Network URL playback
- Playback control (play, pause, seek)
- Volume adjustment
- Event listeners
🛠️ Development
Build the Project
Run Tests
Run Examples
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🤝 Contributing
Issues and Pull Requests are welcome!
📮 Contact
- Project Homepage: https://github.com/Minteea/remu-audio
- Issue Tracker: https://github.com/Minteea/remu-audio/issues
🙏 Acknowledgments
Thanks to the following open source projects:
- rodio - Audio playback library
- symphonia - Audio decoding library
- cpal - Cross-platform audio library
📃 About README
✨ This README was generated with GitHub Copilot ✨