Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

reac native play sound

// Import the react-native-sound module
var Sound = require('react-native-sound');

// Enable playback in silence mode
Sound.setCategory('Playback');

// Load the sound file 'whoosh.mp3' from the app bundle
// See notes below about preloading sounds within initialization code below.
var whoosh = new Sound('whoosh.mp3', Sound.MAIN_BUNDLE, (error) => {
  if (error) {
    console.log('failed to load the sound', error);
    return;
  }
  // loaded successfully
  console.log('duration in seconds: ' + whoosh.getDuration() + 'number of channels: ' + whoosh.getNumberOfChannels());

  // Play the sound with an onEnd callback
  whoosh.play((success) => {
    if (success) {
      console.log('successfully finished playing');
    } else {
      console.log('playback failed due to audio decoding errors');
    }
  });
});

// Reduce the volume by half
whoosh.setVolume(0.5);

// Position the sound to the full right in a stereo field
whoosh.setPan(1);

// Loop indefinitely until stop() is called
whoosh.setNumberOfLoops(-1);

// Get properties of the player instance
console.log('volume: ' + whoosh.getVolume());
console.log('pan: ' + whoosh.getPan());
console.log('loops: ' + whoosh.getNumberOfLoops());

// Seek to a specific point in seconds
whoosh.setCurrentTime(2.5);

// Get the current playback point in seconds
whoosh.getCurrentTime((seconds) => console.log('at ' + seconds));

// Pause the sound
whoosh.pause();

// Stop the sound and rewind to the beginning
whoosh.stop(() => {
  // Note: If you want to play a sound after stopping and rewinding it,
  // it is important to call play() in a callback.
  whoosh.play();
});

// Release the audio player resource
whoosh.release();
Comment

PREVIOUS NEXT
Code Example
Javascript :: react js class component 
Javascript :: toastr fades away disappears immediately quickly 
Javascript :: agrgar atributo con id jquey 
Javascript :: array.find 
Javascript :: clean my react app 
Javascript :: javascript set elements width by tag name 
Javascript :: dividing a number into digits javascript 
Javascript :: sequelize find result as raw json 
Javascript :: how to add row in angular dynamically 
Javascript :: copying table element to clipboard using javascript 
Javascript :: difference 
Javascript :: back press subscriptions i is not a function react native 
Javascript :: get all data in collection firebase react 
Javascript :: index and id together angularjs 
Javascript :: Datatable shows No data available in table in angular 
Javascript :: return then javascript 
Javascript :: vue back image 
Javascript :: javascript ean13 checksum generate 
Javascript :: onclick timer javascript 
Javascript :: like php date("Y-m-d",$value) in javascript 
Javascript :: javascript table show only first n rows 
Javascript :: javascript find area of triangle 
Javascript :: javascript most frequent in a list 
Javascript :: save byte as json string javascript 
Javascript :: javascript modify href attr 
Javascript :: jquery script cdn stackoverflow 
Javascript :: dm discord.js 
Javascript :: close button react 
Javascript :: how to use crypto module in nodejs 
Javascript :: How to make a JSON call to an URL 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =