【问题标题】:EXPO : Export Filesystem to file ,into android folderEXPO:将文件系统导出到文件,进入android文件夹
【发布时间】:2020-01-11 06:23:26
【问题描述】:

早上好, 其实我正在研究这个录音机。

https://snack.expo.io/@riwu/audio-recorder

如何将文件保存到设备的文件夹中,如下载?

谢谢

async _stopRecordingAndEnablePlayback() {
        this.setState({
            isLoading: true,
        });
        try {
            await this.recording.stopAndUnloadAsync();
        } catch (error) {
            // Do nothing -- we are already unloaded.
        }
        const info = await FileSystem.getInfoAsync(this.recording.getURI());

        console.log(`FILE INFO: ${JSON.stringify(info)}`);

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


【问题讨论】:

  • 你可以使用FileSystem
  • 假设你的意思是:FileSystem.writeAsStringAsync。像 FileSystem.writeAsStringAsync(this.recording.getURI(), ?????? ) 但不知道内容有什么用
  • 请使用下载保存文件。
  • 下载请求一个 URL。实际上需要将其存储到本地存储中。我错了吗?
  • 你可以使用MediaLibrary.createAssetAsync(localUri)

标签: react-native expo


【解决方案1】:

添加了这个。它工作!!!!

    takePictureAndCreateAlbum = async () => {

        const asset = await MediaLibrary.createAssetAsync(this.recording.getURI());
        MediaLibrary.createAlbumAsync('Expo', asset)
          .then(() => {
            console.log('Album created!');
          })
          .catch(error => {
            console.log('err', error);
          });
      }

非常感谢!

【讨论】:

  • 在这种情况下,资产不是一个对象吗?意思不应该是:MediaLibrary.createAlbumAsync('Expo',asset.uri)?
  • 确保您也获得了许可。等待 Permissions.askAsync( Permissions.CAMERA_ROLL );此外,令我惊讶的是,上述权限也可以用于存储音频/视频。 (这是我的用例)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-23
  • 2011-06-28
  • 2021-05-26
  • 2010-09-27
  • 2018-11-13
  • 1970-01-01
相关资源
最近更新 更多