const fs = require('fs'); const electron = require('electron'); const dataPath = (electron.app || electron.remote.app).getPath('userData'); const fPath =
${dataPath}/file/unzip`;
const [AudioContext] = [window.AudioContext];
const audioCtx = AudioContext ? new AudioContext() : '';`
getAudioFile() { const self = this; const [audio] = [self.$refs.audio]; audio.src =
${fPath}/${self.id}/${self.list[self.menuIndex].id}/${self.process.infoData.audioURL}; audio.play(); audio.addEventListener('timeupdate', () => { self.countDown(audio.duration, audio.currentTime); }); fs.readFile(
${fPath}/${self.id}/${self.list[self.menuIndex].id}/${self.process.infoData.audioURL}, (err, data) => { if (!err) { self.audioPlay(data); } else { console.log(err); } }, ); }, audioPlay(data) { const self = this; const audioBufferSourceNode = audioCtx.createBufferSource(); audioCtx.decodeAudioData(data.buffer).then((decodedData) => { audioBufferSourceNode.buffer = decodedData; audioBufferSourceNode.connect(audioCtx.destination); console.log(audioBufferSourceNode.buffer.duration); audioBufferSourceNode.start(); self.countDown(Math.ceil(audioBufferSourceNode.buffer.duration)); self.stop = () => { audioBufferSourceNode.stop(); }; audioBufferSourceNode.onended = () => { console.log('end'); }; }); },