How I can access static files outside the project root?

若如初见. 提交于 2020-01-07 09:24:07

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!