Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/421.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在react native中预加载音频文件?_Javascript_Reactjs_React Native_Expo - Fatal编程技术网

Javascript 如何在react native中预加载音频文件?

Javascript 如何在react native中预加载音频文件?,javascript,reactjs,react-native,expo,Javascript,Reactjs,React Native,Expo,我现在正在开发一个媒体播放器,但我渴望找到一个解决方案,在那里我可以预加载前4个音频文件,当我准备下一个时,预加载功能将再次运行。我使用一个数组,每个数组的url路径指向s3 bucket,而不是本地的。我还想提到的是,我正在使用expo av软件包 目前,加载方式如下所示 componentDidMount() { Audio.setAudioModeAsync({ allowsRecordingIOS: false, stays

我现在正在开发一个媒体播放器,但我渴望找到一个解决方案,在那里我可以预加载前4个音频文件,当我准备下一个时,预加载功能将再次运行。我使用一个数组,每个数组的url路径指向s3 bucket,而不是本地的。我还想提到的是,我正在使用
expo av
软件包

目前,加载方式如下所示

componentDidMount() {
        Audio.setAudioModeAsync({
            allowsRecordingIOS: false,
            staysActiveInBackground: false,
            interruptionModeIOS: Audio.INTERRUPTION_MODE_IOS_DO_NOT_MIX,
            playsInSilentModeIOS: true,
            shouldDuckAndroid: true,
            interruptionModeAndroid: Audio.INTERRUPTION_MODE_ANDROID_DO_NOT_MIX,
            playThroughEarpieceAndroid: false
        });
    }

    async _loadNewPlaybackInstance(playing) {
        if (this.playbackInstance != null) {
            await this.playbackInstance.unloadAsync();
            this.playbackInstance = null;
        }

        const source = { uri: PLAYLIST[this.index].url };
        const initialStatus = {
            shouldPlay: playing,
            rate: this.state.rate,
            shouldCorrectPitch: this.state.shouldCorrectPitch,
            volume: this.state.volume,
        };

        const { sound, status } = await Audio.Sound.createAsync(
            source,
            initialStatus,
            this._onPlaybackStatusUpdate
        );
        this.playbackInstance = sound;

        if (status) {
            this._onPlayPausePressed()
        }

        this._updateScreenForLoading(false);
    }

加载页面时,显示指示器,当您完成所有运行音频的功能后,使指示器消失。@Hong,我想您还没有理解我的问题。我不要装载机。我想下载缓存中的文件。所以当我播放第一个音频文件时,前4个音频文件将被下载并存储在缓存中。加载页面时,显示指示器,当您完成所有运行音频的功能后,使指示器消失。@hongdevelop我想您还没有理解我的问题。我不要装载机。我想下载缓存中的文件。所以当我播放第一个音频文件时,前4个音频文件将被下载并存储在缓存中。