【问题标题】:How to play encrypted video in react native offline?如何在离线反应原生中播放加密视频?
【发布时间】:2021-07-12 15:50:30
【问题描述】:

我的本​​地 android 文件中有视频,这些视频是使用 AEC 算法加密的。是否有任何直接的方法可以在 react-native-video 中播放该视频? 我尝试将其转换为 base64 并逐片解密,但 react-native-video 不支持 base64 作为源。 我尝试在 react-native-webview 上播放它,但它不起作用。代码如下

<WebView
            injectedJavaScript={debugging}
            onMessage={(message) => {
              console.log(message);
            }}
            source={{
              baseUrl: '',
              html: `<html>
                 <body>
                    <video width="100%" height="600" controls controlsList="nodownload" autoplay='autoplay' id='myvideo'>
                    <source type="video/mp4" src="data:video/mp4;base64,${videoFile}">
                     </video>
                  </body>
                  <script src="${RNFetchBlob.fs.dirs.MainBundleDir}/bundle.js"></script>
                  <script type="text/javascript">
                    console.log('check is check')
                  </script>
                  <script type="text/javascript">
                    console.log('check is check  32 and this is from the nepal')
                    let data = '';
                    RNFetchBlob.fs
                    .readStream('file:///' + ${allVideoFile[1].path}, 'base64', 102399, 250)
                    .then((stream) => {
                      stream.open();
                      stream.onData((chunk) => {
                        data+=chunk;
                      });
                      stream.onEnd(() => {});
                    }).catch(err=>{
                      console.log('Error is',err)
                    })
                    console.log('data is',data)
                  </script>
               </html>`,
            }}
          />

我从搜索中尝试了各种其他解决方案,但没有任何帮助。我不知道我在这里错过了什么。

【问题讨论】:

    标签: react-native react-native-webview react-native-video react-native-fetch-blob


    【解决方案1】:

    所以我在我的应用程序中做了这样的事情,我会给你指示:

    1. 使用react-native-fs获取视频文件base64
    2. 解密并使用react-native-fs将其存储在 DocumentDirectoryPath 中(此路径在 react-native-fs 中预定义)
    3. react-native-video可以读取base64文件所以直接放路径source={{ uri: videoUrl }}

    让我知道它是否适合你。

    干杯。

    【讨论】:

    • 嗨 @Aymen 无法播放 base64 文件。正如您在上面添加的那样
    猜你喜欢
    • 2018-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多