Skip to main content

useMuted()

useMuted(): boolean

Returns whether the player is currently muted.

This hook provides a reactive way to observe and respond to changes in the player's mute state — useful for updating UI elements (e.g., toggling a mute/unmute button) or running logic based on whether sound is enabled.

You can control this state using:

  • player.setMuted(true) — mutes the player.
  • player.setMuted(false) — unmutes the player.

The setMuted(newMuted) method returns a Promise<void> and updates the player’s audio output state asynchronously.

⚠️ Must be used within a PlayerProvider or AVPlayerViewControllerProvider component.

Returns

boolean

boolean true if the player is muted, otherwise false.

Example

import React from 'react';
import { View, Text, Button } from 'react-native';
import { usePlayer, useMuted } from '@castlabs/react-native-prestoplay';

export default function MuteToggle() {
const player = usePlayer();
const muted = useMuted();

const toggleMute = async () => {
await player.setMuted(!muted);
};

return (
<View>
<Text>{muted ? 'Muted 🔇' : 'Unmuted 🔊'}</Text>
<Button
title={muted ? 'Unmute' : 'Mute'}
onPress={toggleMute}
/>
</View>
);
}