Skip to navigation

Adjust volume and mute

Learn how to monitor and respond to volume and mute state changes in the FastPix iOS Player.

The FastPix iOS Player lets you control volume and mute from your own UI, and provides delegate callbacks so a custom UI stays in sync with the player’s audio state.

Control the volume

The player respects the device’s system volume, so changes made with the hardware volume buttons apply during playback with no extra setup. To drive volume from your own UI, such as a slider or gesture, set the player’s volume directly. The range is 0.0 (mute) to 1.0 (maximum), and it applies to the SDK player instance.

// Update the player's volume based on the slider value
// Range: 0.0 (mute) to 1.0 (maximum volume)
playerViewController.setVolume(sender.value)
// Update the mute/unmute icon depending on whether volume is zero
// If slider value is 0, treat the player as muted
updateMuteIcon(isMuted: sender.value == 0)

Mute and unmute

toggleMute() mutes or unmutes instantly without changing the current volume level, which is useful for a mute button or an accessibility control. Read the current state with isMuted().

// Toggle the mute state of the player
// If currently playing audio, it will mute; if muted, it will unmute
playerViewController.toggleMute()
// Fetch the updated mute state after toggling
let isMuted = playerViewController.isMuted()

Listen to volume changes

Implement the following delegate method to receive notifications when the player’s volume level changes. The volume value ranges from 0.0 (silent) to 1.0 (maximum).

func onVolumeChanged(
_ player: AVPlayerViewController,
volume: Float
) {
// Volume range: 0.0 (silent) to 1.0 (max)
print("[Volume] Volume changed to \(volume)")
}

Listen to mute state changes

Implement this delegate method to detect when the player is muted or unmuted:

func onMute(
_ player: AVPlayerViewController,
isMuted: Bool
) {
// true = muted, false = unmuted
print("[Volume] Mute state changed: \(isMuted)")
}

Use these callbacks to update custom volume sliders, mute icons, or other UI elements so they stay in sync with the player’s audio state.