小编Tee*_*dub的帖子

在React Native中将屏幕锁定在Android上时,如何播放声音?

我有一个简单的应用程序,渲染后几秒钟即可播放声音。

一切正常,除了如果我锁定屏幕,应用程序将不会播放声音,直到我再次将其解锁。

这是我正在使用的简化版本:

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)

javascript android react-native react-native-android

6
推荐指数
0
解决办法
547
查看次数