Media
Use this integration to control the system volume and receive events when volume changes occur.
Introduction
This module provides control over the system’s media, such as audio volume settings and event when volume changes occur. It allows you to programmatically adjust the volume, query the current volume level, and receive events when the volume is changed through any means.
Where to find: startiapp.Media
Methods
setVolume
setVolume(newVolume: number): Promise<void>
Sets the system volume to the specified value.
newVolume
: A number between 0 and 1 representing the desired volume level (0 = muted, 1 = maximum volume)
getVolume
getVolume(): Promise<number>
Gets the current system volume level. Returns: A number between 0 and 1 representing the current volume level.
increaseVolume
increaseVolume(): Promise<void>
Increases the system volume by one step.
decreaseVolume
decreaseVolume(): Promise<void>
Decreases the system volume by one step.
Events
volumeChanged
interface VolumeChangedEventArgs {
volume: number;
}
Fired when the system volume changes. The event detail contains:
volume
: The new volume level (between 0 and 1)
Examples
Basic Usage
// Set volume to 50%
await startiapp.Media.setVolume(0.5);
// Get current volume
const volume = await startiapp.Media.getVolume();
console.log(`Current volume: ${volume * 100}%`);
// Listen for volume changes
startiapp.Media.addEventListener('volumeChanged', (event) => {
const newVolume = event.detail.volume;
console.log(`Volume changed to: ${newVolume * 100}%`);
});
Volume Control
// Increase volume
await startiapp.Media.increaseVolume();
// Decrease volume
await startiapp.Media.decreaseVolume();
Monitor Volume Changes
class VolumeMonitor {
constructor() {
startiapp.Media.addEventListener('volumeChanged', this.handleVolumeChange);
}
private handleVolumeChange = (event: CustomEvent<VolumeChangedEventArgs>) => {
const newVolume = event.detail.volume * 100;
console.log(`System volume is now at ${newVolume}%`);
}
public cleanup() {
startiapp.Media.removeEventListener('volumeChanged', this.handleVolumeChange);
}
}