Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}), () => {
// 第一次播放时还没有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 })
});
["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);
}
});
});
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
const initializeSound = (name: string) => {
return new ReactNativeSound(name, ReactNativeSound.MAIN_BUNDLE, err => {
if (err) {
console.warn('failed to load the sound', err);
}
});
};
setInterval(() => {
if (this.state.secondsUntilWake > 0 && this.state.timePicked === true) {
this.setState({secondsUntilWake: this.state.secondsUntilWake - 5})
}
if (this.state.secondsUntilWake === 0) {
//sound to play when alarm goes off with error handling
let alarm = new Sound('tone.mp3', Sound.MAIN_BUNDLE, (error) => {
if (error) {
console.log('error:', error);
} else {
alarm.play();
}
});
}
}, 5000);
}
import Sound from 'react-native-sound'
const SOUND_FILE_NAME = 'tin2.mp3'
const ting = new Sound(SOUND_FILE_NAME, Sound.MAIN_BUNDLE, (error) => {
if (error) {
console.log('cant load sound', SOUND_FILE_NAME)
}
})
export default class {
static play() {
ting.play()
}
static playTwice() {
ting.play()
const timeoutId = setTimeout(() => {
ting.stop()
const innerId = setTimeout(() => {
ting.play()
const Sound = require("react-native-sound");
const FailureCat = new Sound("angry_cat.mp3", Sound.MAIN_BUNDLE, error => {});
const FailureDog = new Sound("angry_dog.was", Sound.MAIN_BUNDLE, error => {});
export const playFailureCat = () => {
if (FailureCat.isPlaying) {
FailureCat.stop(() => FailureCat.play());
} else {
FailureCat.play();
}
};
export const playFailureDog = () => {
if (FailureDog.isPlaying) {
FailureDog.stop(() => FailureDog.play());
} else {
FailureDog.play();
}
};
import React, { Component, PropTypes } from 'react';
import { Dimensions, View, StyleSheet } from 'react-native';
import { Chess } from 'chess.js';
import Sound from 'react-native-sound';
import Square from './Square';
import Piece from './Piece';
const screenWidth = Dimensions.get('window').width;
const DIMENSION = 8;
const COLUMN_NAMES = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'];
const moveSound = new Sound('move.mp3', Sound.MAIN_BUNDLE);
const captureSound = new Sound('capture.mp3', Sound.MAIN_BUNDLE);
export default class BoardView extends Component {
static propTypes = {
fen: PropTypes.string,
size: PropTypes.number.isRequired,
showNotation: PropTypes.bool,
color: PropTypes.oneOf(['w', 'b']),
shouldSelectPiece: PropTypes.func,
onMove: PropTypes.func,
style: View.propTypes.style,
};
static defaultProps = {
size: screenWidth - 32,
showNotation: true,
);
const resultIcons = {
'': '',
pending: '?',
playing: '\u25B6',
win: '\u2713',
fail: '\u274C',
};
const audioTests = [
{
title: 'mp3 in bundle',
url: 'advertising.mp3',
basePath: Sound.MAIN_BUNDLE,
},
{
title: 'mp3 in bundle (looped)',
url: 'advertising.mp3',
basePath: Sound.MAIN_BUNDLE,
onPrepared: (sound, component) => {
sound.setNumberOfLoops(-1);
component.setState({loopingSound: sound});
},
},
{
title: 'mp3 via require()',
isRequire: true,
url: require('./advertising.mp3'),
},
{
return new Promise((resolve, reject) => {
const locale = localeOrder.shift();
const audioUrl = Platform.select({
ios: `audio/${audioID}/${audioID}${locale}.mp3`,
android: `audio_${audioID}${locale.toLowerCase()}.mp3`,
});
this.unloadAudio();
this._loadedSound = new Sound(audioUrl, Sound.MAIN_BUNDLE, error => {
if (error) {
this.unloadAudio();
if (localeOrder.length === 0) {
reject(`Cannot load file: ${audioUrl}`);
return;
}
resolve(
this.loadAudio({
audioID,
localeOrder,
playAudioAfterLoad,
}),
);
}