How to use react-native-sound - 10 common examples

To help you get started, we’ve selected a few react-native-sound examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github okoala / 30DaysofReactNative / Project08-RandomGradientColorMusic / index.js View on Github external
_playMusic () {
    const self = this

    if (!this.music) {
      this.music = new Sound('Ecstasy.mp3', Sound.MAIN_BUNDLE, (error) => {
        if (error) {
          console.log('failed to load the sound', error)
        } else { // loaded successfully
          console.log('duration in seconds: ' + self.music._duration +
              'number of channels: ' + self.music._numberOfChannels)
          // 无线循环播放
          self.music.setNumberOfLoops(-1).play()
        }
      })
    } else {
      this.music.play()
    }
  }
github EdgeApp / edge-react-gui / src / lib / soundsMiddleware.js View on Github external
// @flow

import Sound from 'react-native-sound'

import { OPEN_AB_ALERT } from '../../src/constants/ActionConstants'
import type { Action } from '../modules/ReduxTypes.js'
import { DISPLAY_TRANSACTION_ALERT } from '../modules/UI/components/TransactionAlert/actions'

const AUDIO_RECEUVED_FILE = 'audio_received.mp3'
const AUDIO_SEND_FILE = 'audio_sent.mp3'

Sound.setCategory('Ambient')

const audioReceived = new Sound(AUDIO_RECEUVED_FILE, Sound.MAIN_BUNDLE, error => {
  if (error) console.warn(`failed to load the sound ${AUDIO_RECEUVED_FILE}`, error)
})

const audioSent = new Sound(AUDIO_SEND_FILE, Sound.MAIN_BUNDLE, error => {
  if (error) console.error(`failed to load the sound ${AUDIO_SEND_FILE}`, error)
})

const playCb = audioName => success => {
  if (success) {
    console.info(`successfully finished playing ${audioName}`)
  } else {
    console.warn(`playback ${audioName} failed due to audio decoding errors `)
  }
}

export default () => (next: Function) => (action: Action) => {
github rico-c / NeatMusic / NeatMusic / src / page / player.js View on Github external
}), () => {
                    // 第一次播放时还没有whoosh对象,需要判断
                    if (this.whoosh.release) { this.whoosh.release() };
                    this.whoosh = new Sound(this.state.uri, Sound.MAIN_BUNDLE, (error) => {
                        if (error) {
                            console.log('failed to load the sound', error);
                            return;
                        }
                        this.whoosh.setVolume(1);
                        this.whoosh.setNumberOfLoops(-1);
                        // 播放完成后的回调,当Loops为无限时不会触发
                        this.whoosh.play((success) => {
                            if (success) {
                                store.dispatch(controlPlay(store.getState().songOrder + 1));
                            } else {
                                this.whoosh.reset();
                            }
                        });
                        this.setState({ playing: true })
                    });
github shellfly / AwesomeProject / app / utils / soundPlayer.js View on Github external
["chord_nice", "chord_prompt", "right_answer", "wrong_answer"].forEach((s) => {
  // Load the sound file  from the app bundle
  // Have to add mp3 files to project and restart simulator
  sounds[s] = new Sound(`${s}.mp3`, Sound.MAIN_BUNDLE, (error) => {
    if (error) {
      console.log("failed to load the sound", error);
    }
  });
});
github goodatlas / react-native-audio-record / Example / App1.js View on Github external
play = async () => {
    if (!this.state.loaded) {
      try {
        await this.load();
      } catch (error) {
        console.log(error);
      }
    }

    this.setState({ paused: false });
    Sound.setCategory('Playback');

    this.sound.play(success => {
      if (success) {
        console.log('successfully finished playing');
      } else {
        console.log('playback failed due to audio decoding errors');
      }
      this.setState({ paused: true });
      // this.sound.release();
    });
  };
github EdgeApp / edge-react-gui / src / lib / soundsMiddleware.js View on Github external
// @flow

import Sound from 'react-native-sound'

import { OPEN_AB_ALERT } from '../../src/constants/ActionConstants'
import type { Action } from '../modules/ReduxTypes.js'
import { DISPLAY_TRANSACTION_ALERT } from '../modules/UI/components/TransactionAlert/actions'

const AUDIO_RECEUVED_FILE = 'audio_received.mp3'
const AUDIO_SEND_FILE = 'audio_sent.mp3'

Sound.setCategory('Ambient')

const audioReceived = new Sound(AUDIO_RECEUVED_FILE, Sound.MAIN_BUNDLE, error => {
  if (error) console.warn(`failed to load the sound ${AUDIO_RECEUVED_FILE}`, error)
})

const audioSent = new Sound(AUDIO_SEND_FILE, Sound.MAIN_BUNDLE, error => {
  if (error) console.error(`failed to load the sound ${AUDIO_SEND_FILE}`, error)
})

const playCb = audioName => success => {
  if (success) {
    console.info(`successfully finished playing ${audioName}`)
  } else {
    console.warn(`playback ${audioName} failed due to audio decoding errors `)
  }
}
github zmxv / react-native-sound-demo / main.js View on Github external
return;
    }
    setTestState(testInfo, component, 'playing');
    // Run optional pre-play callback
    testInfo.onPrepared && testInfo.onPrepared(sound, component);
    sound.play(() => {
      // Success counts as getting to the end
      setTestState(testInfo, component, 'win');
      // Release when it's done so we're not using up resources
      sound.release();
    });
  };

  // If the audio is a 'require' then the second parameter must be the callback.
  if (testInfo.isRequire) {
    const sound = new Sound(testInfo.url, error => callback(error, sound));
  } else {
    const sound = new Sound(testInfo.url, testInfo.basePath, error => callback(error, sound));
  }
}
github duytq94 / react-native-fb-reactions-animation / App / Containers / Animation / Animation.Screen.js View on Github external
constructor (props) {
    super(props)
    this.backPress = this.handleBackPress.bind(this)

    this.soundBoxDown = new Sound('box_down.mp3', Sound.MAIN_BUNDLE, (error) => { })
    this.soundBoxUp = new Sound('box_up.mp3', Sound.MAIN_BUNDLE, (error) => { })
    this.soundIconChoose = new Sound('icon_choose.mp3', Sound.MAIN_BUNDLE, (error) => { })
    this.soundIconFocus = new Sound('icon_focus.mp3', Sound.MAIN_BUNDLE, (error) => { })
    this.soundShortTouchLike = new Sound('short_press_like.mp3', Sound.MAIN_BUNDLE, (error) => { })

    // Slow down speed animation here (1 = default)
    this.timeDilation = this.props.navigation.state.params.speed

    // If duration touch longer than it, mean long touch
    this.durationLongPress = 250

    // Variables to check
    // 0 = nothing, 1 = like, 2 = love, 3 = haha, 4 = wow, 5 = sad, 6 = angry
    this.isTouchBtn = false

    this.isLongTouch = false
    this.isLiked = false
    this.whichIconUserChoose = 0
    this.currentIconFocus = 0
    this.previousIconFocus = 0
github duytq94 / react-native-fb-reactions-animation / App / Containers / Animation / Animation.Screen.js View on Github external
constructor (props) {
    super(props)
    this.backPress = this.handleBackPress.bind(this)

    this.soundBoxDown = new Sound('box_down.mp3', Sound.MAIN_BUNDLE, (error) => { })
    this.soundBoxUp = new Sound('box_up.mp3', Sound.MAIN_BUNDLE, (error) => { })
    this.soundIconChoose = new Sound('icon_choose.mp3', Sound.MAIN_BUNDLE, (error) => { })
    this.soundIconFocus = new Sound('icon_focus.mp3', Sound.MAIN_BUNDLE, (error) => { })
    this.soundShortTouchLike = new Sound('short_press_like.mp3', Sound.MAIN_BUNDLE, (error) => { })

    // Slow down speed animation here (1 = default)
    this.timeDilation = this.props.navigation.state.params.speed

    // If duration touch longer than it, mean long touch
    this.durationLongPress = 250

    // Variables to check
    // 0 = nothing, 1 = like, 2 = love, 3 = haha, 4 = wow, 5 = sad, 6 = angry
    this.isTouchBtn = false

    this.isLongTouch = false
github bailabs / tailpos / src / container / SalesContainer / index.js View on Github external
// TailOrder
import {
  voidLine,
  sendOrder,
  printOrder,
  cancelOrder,
  tailOrderLine,
  changeOrderTable,
  getOrder,
  orderItemToReceiptItem,
} from "../../services/tailorder";

import { currentLanguage } from "../../translations/CurrentLanguage";
const Sound = require("react-native-sound");
Sound.setCategory("Playback");
const beep = new Sound("beep.mp3", Sound.MAIN_BUNDLE);
import translation from "../.././translations/translation";
import LocalizedStrings from "react-native-localization";
let strings = new LocalizedStrings(translation);
@inject(
  "itemStore",
  "customerStore",
  "receiptStore",
  "discountStore",
  "categoryStore",
  "paymentStore",
  "printerStore",
  "shiftStore",
  "attendantStore",
  "stateStore",
)