Overview
Rive animations can include audio assets that play during animation playback. The iOS Runtime allows you to adjust the volume of these audio assets through thevolume property on RiveModel and RiveArtboard.
Volume Property
The volume is controlled through aFloat property with a range typically from 0.0 (muted) to 1.0 (full volume):
Default Volume
The runtime defaults to full volume (1.0) when no volume is explicitly set:
Setting Volume with RiveModel
TheRiveModel class provides a volume property:
Volume with RiveViewModel (SwiftUI)
For SwiftUI applications usingRiveViewModel:
Complete SwiftUI Example
UIKit Example
Volume Persistence
TheRiveModel stores the volume value internally. When you set an artboard, the stored volume is applied:
Artboard-Level Volume Control
You can also control volume directly on the artboard:RiveModel.
Volume Range
While the typical range is0.0 to 1.0:
0.0= Completely muted0.5= Half volume1.0= Full volume (default)
Best Practices
- Set Volume Early: Configure volume before or immediately after loading the Rive file
- Save User Preferences: Persist volume settings using
UserDefaultsor similar - Respect System Volume: The Rive volume is relative to the system volume
- Provide UI Controls: Give users slider controls for fine-tuned volume adjustment
- Mute State: Implement separate mute functionality rather than just setting volume to 0
- Initial Volume: Consider starting with a lower volume (e.g., 0.5) to avoid startling users
Common Patterns
Volume Presets
Fade In/Out
Volume Persistence
Troubleshooting
Audio Not Playing
- Verify the Rive file contains audio assets
- Check that volume is not set to 0.0
- Ensure device volume is not muted
- Verify audio session is configured correctly
Volume Changes Not Taking Effect
- Set volume after the artboard is loaded
- Access volume through
RiveModelrather than artboard directly - Ensure you’re modifying the correct model instance
Audio Session Configuration
For proper audio playback, configure your app’s audio session:See Also
- RiveModel - Working with Rive models
- Performance - Optimizing Rive animations