问题
I'm developing an app with Electron and React, it's kind of mp3 player. The problem is that I want to play audios that are not in the project folder. How can I upload these files from my hard drive?
import React from 'react';
import Sound from 'react-sound';
class App extends React.Component {
render() {
return (
<Sound
url='/media/user/Vol/a.mp3'
playStatus={Sound.status.PLAYING}
playFromPosition={300}
onLoading={this.handleSongLoading}
onPlaying={this.handleSongPlaying}
onFinishedPlaying={this.handleSongFinishedPlaying}
/>
)
}
}
export default App;
I tried to set the url like file:///media/user/Vol/a.mp3
, but it doesn't work.
回答1:
Of course Electron can speak to files outside its project root. It wouldn't be any good for making desktop apps if it couldn't.
There are a few ways to do this in Electron.
The dialog API lets you present the user with standard File Open dialogs from their OS.
The File Object API lets you speak directly to files on the filesystem.
And the shell API allows you to run native commands, such as launching a native MP3 player.
来源:https://stackoverflow.com/questions/59474847/how-i-can-access-static-files-outside-the-project-root