gpt4 book ai didi

android - react-native ios app webview 在屏幕关闭时播放静音

转载 作者:行者123 更新时间:2023-11-29 11:31:18 27 4
gpt4 key购买 nike

我构建了一个 react-native webview 应用程序,当屏幕关闭时它有音频在 ios 中关闭时在 android 中继续播放音频。有什么解决办法吗?

最佳答案

请确保Xcode 项目的Background Modes 已启用。

如果未启用,请转到 Xcode 项目 -> 选择目标 -> 功能部分 -> 背景模式 -> 将其打开。

然后选择音频、AirPlay 和画中画

enter image description here

代码:

import React, { Component } from 'react';
import {StyleSheet, View, Button} from 'react-native';
import SoundPlayer from 'react-native-sound-player';

export default class Touchables extends Component {
constructor(props) {
super(props);
}

playTrack() {
try {
SoundPlayer.playUrl('http://file-examples.com/wp-content/uploads/2017/11/file_example_MP3_700KB.mp3')
} catch (e) {
alert('Cannot play the file')
console.log('cannot play the song file', e)
}
}

render() {
return (
<View style={styles.container}>
<Button title="play me" onPress={this.playTrack} />
</View>
);
}
}

const styles = StyleSheet.create({
container: {
marginTop: 100,
},
});

关于android - react-native ios app webview 在屏幕关闭时播放静音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53237714/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com