Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Taro.chooseVideo选择视频后返回的文件路径如何转成base64 #10102

Closed
Jidahan opened this issue Aug 23, 2021 · 1 comment
Closed
Labels
F-react Framework - React T-rn Target - 编译到 React Native V-3 Version - 3.x

Comments

@Jidahan
Copy link

Jidahan commented Aug 23, 2021

相关平台

React Native

使用框架: React

复现步骤

 Taro.chooseVideo({
        sourceType: ['album','camera'],
        maxDuration: 8,
        camera: 'front',
        success: function (res) {
          res.tempFilePath.replace('.mov', '.mp4')
                    var file = new File([res.tempFilePath], "video.mp4" ,{type: "video/mp4", lastModified: new Date});
                    console.log(file);
                    const fileReader = new FileReader()
                    fileReader.readAsDataURL(file)
                    fileReader.onload = function () { 
                      const base64 = this.result.substring(this.result.indexOf(',') 1)
                      console.log(base64);
          }
       }

期望结果

选择视频后,最后返回一个base64

实际结果

我现在是这样写的,虽然最后能输出一个很像base64的编码,但是解码后是坏的不能用

环境信息

Taro v3.3.2


  Taro CLI 3.3.2 environment info:
    System:
      OS: macOS 11.5.1
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 14.17.4 - /usr/local/bin/node
      Yarn: 1.22.11 - /usr/local/bin/yarn
      npm: 6.14.14 - /usr/local/bin/npm
    npmPackages:
      @tarojs/components: 3.3.2 => 3.3.2 
      @tarojs/mini-runner: 3.3.2 => 3.3.2 
      @tarojs/react: 3.3.2 => 3.3.2 
      @tarojs/runtime: 3.3.2 => 3.3.2 
      @tarojs/taro: 3.3.2 => 3.3.2 
      @tarojs/webpack-runner: 3.3.2 => 3.3.2 
      babel-preset-taro: 3.3.2 => 3.3.2 
      eslint-config-taro: 3.3.2 => 3.3.2 
      react: ^17.0.0 => 17.0.2 
      react-native: ^0.64.0 => 0.64.2 
@taro-bot2 taro-bot2 bot added F-react Framework - React T-rn Target - 编译到 React Native V-3 Version - 3.x labels Aug 23, 2021
@zhiqingchen
Copy link
Member

https://github.com/tanersener/react-native-ffmpeg
可对视频做转码,再转base64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-react Framework - React T-rn Target - 编译到 React Native V-3 Version - 3.x
Projects
None yet
Development

No branches or pull requests

2 participants