A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/remigallego/react-native-use-sound below:

remigallego/react-native-use-sound: useSound 🔊 A React Native hook for playing sounds 🔊

useSound - react-native-use-sound 🔊 A React Native Hook for playing sounds 🔊

react-native-use-sound is largely based on the work by @joshwcomeau use-sound

âš  You must first install react-native-sound âš 

npm i react-native-sound
cd ios && pod install

Then, our Hook can be added:

npm install react-native-use-sound
import useSound from "react-native-use-sound";
import { Button } from "react-native";

const MusicButton = () => {
  const coolMusic =
    "http://commondatastorage.googleapis.com/codeskulptor-demos/DDR_assets/Kangaroo_MusiQue_-_The_Neverwritten_Role_Playing_Game.mp3";
  const [play, pause, stop, data] = useSound(coolMusic);

  const handlePlay = () => {
    if (data.isPlaying) pause();
    else play();
  };

  return (
  <>
    <Button
      title={data.isPlaying ? "Pause" : "Play"}
      onPress={handlePlay} 
    />
    <Button
      title={"Stop"}
      onPress={stop} 
    />
  </>
  );
};

The useSound hook takes two arguments:

It produces an array with four values:

When calling useSound, you can pass it a variety of options:

Name Value volume number interrupt boolean soundEnabled boolean timeRate number numberOfLoops boolean

The hook produces a tuple with 4 options, the play, pause, stop functions and an Data object:

const [play, pause, stop, data] = useSound("/meow.mp3");
//                        ^ What we're talking about
Name Value sound Sound seek function ((sec: number) => void) isPlaying boolean duration number currrentTime number loading boolean

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4