Я создал собственное приложение для веб-просмотра, которое воспроизводит звук, когда экран выключается, звук продолжает воспроизводиться в Android, пока он выключен в IOS. есть ли решение?
Убедитесь, что проект Background Modes из Xcode включен.
Background Modes
Xcode
Если не включено, перейдите в проект Xcode -> Выберите цель -> раздел Возможности -> Фоновые режимы -> Включите его.
Затем выберите Audio, AirPlay, and Picture in Picture.
Audio, AirPlay, and Picture in Picture
Код:
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, }, });