使用 wavesurfer.js 和 react-native-webview

问题描述

我正在尝试在 react-native-webview 组件中使用 wavesurfer.js。如果我在浏览器中按原样打开它,html 可以正常工作,但在 webview 中它不起作用。 WaveSurfer 以未定义的形式回归。我在 webview 中使用了基本的网络音频内容,所以不是这样。

<WebView
          originWhitelist={'["*"]'}
          ref={ref => (this.webview = ref)}
          injectedJavaScriptBeforeContentLoaded={runFirst}
          javaScriptEnabled = {true}
          domStorageEnabled={true}
          scalesPagetoFit={true}
          scrollEnabled={false}
          originWhitelist={['*']}
          allowUniversalAccessFromFileURLs={true}
          allowFileAccessFromFileURLs={true}
          allowFileAccess={true}
          onMessage={this.onMessage}            
          source={{ html: 
            `<html>
              <body style="background-color: #2a282b" >
                <div id="waveform"></div>
              </body>
              <script src="https://unpkg.com/wavesurfer.js">
              </script>
              <script>
                var wavesurfer = WaveSurfer.create({
                  container: document.querySelector('#waveform'),barWidth: 1,barHeight: 1,});
                wavesurfer.load('http://ia902606.us.archive.org/35/items/shortpoetry_047_librivox/song_cjrg_teasDale_64kb.mp3');
              </script>
            </html>`
          }}
        />

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)