aadsm / jsmediatags

Media Tags Reader (ID3, MP4, FLAC)
Other
748 stars 128 forks source link

Add support for React-Native [Request] #82

Open dannydolph opened 6 years ago

dannydolph commented 6 years ago

I'm using jsmediatags in an React-Native application (a music player) and I get this error as soon as I require or import this package : bundling failed: UnableToResolveError: Unable to resolve module 'fs'

aadsm commented 6 years ago

@dannydolph you’ll need to use a library like react-native-fs to read the filesystem, the fs library is native to node and it will not exist in an environment like react native. This basically means that you can’t use the NodeFileReader class to read the files. You’ll need to implement a new one that specifically knows how to read files in RN. You should be able to use NodeFileReader as a template. It would also be great if you can contribute with this new reader to the repo :)).

davidroeca commented 6 years ago

@aadsm I'm currently taking a stab at this and there are a couple of hurdles that are difficult.

  1. React-Native is built with node/babel, so the build2 directory needs to ignore the NodeFileReader or the build error will still exist. This differs from the browserify solution ignoring the NodeFileReader since the build pipeline is different.
  2. Conditional requires aren't supported by react-native so I'm not sure how to deal with conditional builds for the node vs React-Native versions.
  3. react-native-fs is promise-based. Support for promises with this library would be nice. Translating between callbacks/promises works but is a bit awkward.
  4. Not sure what encoding should be used--music files are binary and react-native-fs recommends base64 for binary, but I'm not sure if the tags are treated differently or what this library expects.

Here's my current implementation https://github.com/davidroeca/jsmediatags/blob/react-native/src/ReactNativeFileReader.js

Let me know if you have any insight on any of the above.