久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在 electron 中打開本地文件并在 wavesurfer.js 中渲染

Open local file in electron and render in wavesurfer.js(在 electron 中打開本地文件并在 wavesurfer.js 中渲染)
本文介紹了在 electron 中打開本地文件并在 wavesurfer.js 中渲染的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在開發一個使用電子構建的應用程序,它應該與 wavesurfer.js 一起使用以顯示代表音頻文件的波形.但是,我無法使用 fs 模塊打開文件并通過 Blob 將文件內容推送到 wavesurfer.文件加載,一切似乎都正常,但是當解碼 wavesurfer 時說 Errordecode audiobuffer.

I'm working on an app built with electron, it should work with wavesurfer.js to display a waveform representing the audio file. However, I'm having trouble opening the file using the fs module and pushing the file content to wavesurfer via a Blob. The file loads and everything seems to work but when decoding wavesurfer says Error decoding audiobuffer.

我認為可能會影響這一點的兩件事:

Two things I thought maybe could influence this:

  • fs.readFile 函數將編碼作為第二個參數
  • Blob 構造函數將選項對象作為第二個參數,在此您可以通過 type 屬性定義 mimetype
  • The fs.readFile function takes an encoding as second parameter
  • The Blob constructor takes an options object as second parameter, whithin this you can define the mimetype via the type property

但是,到目前為止,這兩種方法都未能解決問題.

However, until now both approaches have failed to fix the problem.

我希望有人有解決方案.(也可能是 fs.readFile 函數完全是錯誤的方法,還有更好的方法;我只是在尋找一種相對高效的打開文件的方法,不勝感激)干杯!

I hope somebody has a solution. (Could also be the fs.readFile function is entirely the wrong way to go and there's a much better way; I'm just looking for a relatively performant way of opening a file, any help is appreciated) Cheers!

這是代碼……

(我省略了所有電子樣板,您可以通過 git clone https://github.com/sindresorhus/electron-boilerplate/ 輕松獲得它) - 包含一個腳本標簽到 index.html 中的 main.js,在 html 的某處添加一個 id 為 wave-area 的 div 并添加一個 script 標簽到wavesurfer.js 庫.您還需要 demo wav 文件的本地副本.

(I'm leaving out all the electron boilerplate, you can get it easily by doing git clone https://github.com/sindresorhus/electron-boilerplate/) – Include a script tag to main.js in the index.html, add a div with the id wave-area somewhere in the html and add a script tag to the the wavesurfer.js library. Also you will need a local copy of the demo wav-file.

然后在main.js文件中……

var fs = require('fs');

var wavesurfer = Object.create(WaveSurfer);
wavesurfer.init({
  container: '#wave-area'
});

fs.readFile('/path/to/demo.wav', function(err, data) {
  if (data && !err) {
    console.log('has data and no error!');
  }
  var file = new window.Blob([data]);
  wavesurfer.loadBlob(file);
}

wavesurfer.on('loading', function(e) {
  console.log('loading', e);
});

wavesurfer.on('error', function(err) {
  console.log(err);
});

推薦答案

我終于找到了解決方案!通過 loadBlob 方法傳遞給 wavesurfer 的 blob 需要轉換為 Uint8Array

I finally found the solution! The blob which is passed to wavesurfer through the loadBlob method needs to transformed into an Uint8Array

工作代碼如下所示

fs.readFile('/path/to/demo.wav', function(err, buffer) {
  // …
  var blob = new window.Blob([new Uint8Array(buffer)]);
  wavesurfer.loadBlob(blob);
}

這篇關于在 electron 中打開本地文件并在 wavesurfer.js 中渲染的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to fix BrowserWindow is not a constructor error when creating child window in Electron renderer process(在 Electron 渲染器進程中創建子窗口時如何修復 BrowserWindow 不是構造函數錯誤) - IT屋-程序員軟件開發技術
mainWindow.loadURL(quot;https://localhost:3000/quot;) show white screen on Electron app(mainWindow.loadURL(https://localhost:3000/) 在 Electron 應用程序上顯示白屏)
Electron webContents executeJavaScript : Cannot execute script on second on loadURL(Electron webContents executeJavaScript:無法在第二個 loadURL 上執行腳本)
how to use electron browser window inside components in angular-cli?(如何在angular-cli的組件內使用電子瀏覽器窗口?)
ElectronJS - sharing redux store between windows?(ElectronJS - 在 Windows 之間共享 redux 存儲?)
How to access camera/webcamera inside electron app?(如何在電子應用程序中訪問相機/網絡攝像頭?)
主站蜘蛛池模板: 一级毛片在线视频 | 精品久久ai电影 | 亚洲免费成人 | 亚洲成人av | 久久久精品 | 天天干天天爽 | 91视视频在线观看入口直接观看 | 99久久久久久 | 日本久久网 | 国产成人精品福利 | 伊人狠狠| 国产高清视频 | 国产免费福利小视频 | 亚洲国产精品人人爽夜夜爽 | 99reav| 国产不卡一区 | 国产成人精品久久久 | 亚洲成人午夜电影 | 国产一级大片 | 欧美一级二级在线观看 | 亚洲人成人一区二区在线观看 | 成人免费在线视频 | 亚洲网站在线播放 | 欧美久久精品一级c片 | 播放一级黄色片 | 欧美一区二区三区在线观看 | 久久综合狠狠综合久久综合88 | 日韩插插 | 在线免费观看a级片 | www国产精品 | 国产超碰人人爽人人做人人爱 | 久久99久久久久 | 综合一区二区三区 | 日韩av成人 | 日韩久久久久久久久久久 | 亚洲欧美成人影院 | 亚洲一区二区三区视频 | 久久精品视频免费看 | 国产农村妇女毛片精品久久麻豆 | 91亚洲精选| 国产资源在线视频 |