我有一个简单的应用程序,渲染后几秒钟即可播放声音。
一切正常,除了如果我锁定屏幕,应用程序将不会播放声音,直到我再次将其解锁。
这是我正在使用的简化版本:
import React, { Component, PropTypes } from 'react';
import { View, Text } from 'react-native';
import Sound from 'react-native-sound'; //for the bell sound
class SoundTest extends Component {
componenWillMount(){
setTimeout(this.playSound(), 5000);
}
playSound() {
let s = new Sound('bell.wav','', (e) => {
if (e) {
console.log('error', e);
} else {
console.log('duration', s.getDuration());
s.play();
}
});
}
render() {
return (
<View>
<Text>Hear some sound after a few!</Text>
</View>
)
}
}
AppRegistry.registerComponent('SoundTest', () => SoundTest);
// Works …Run Code Online (Sandbox Code Playgroud)