Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache for ios ? #282

Closed
thalwani opened this issue Sep 15, 2018 · 15 comments
Closed

Cache for ios ? #282

thalwani opened this issue Sep 15, 2018 · 15 comments

Comments

@thalwani
Copy link

Hello,

Is it possible to have cache for ios too ? I would like to reduce the bandwidth consumption by downloading the track only the first time the user listen to it.

Thank you.

Regards,
Toufic.

@mateomorris
Copy link

I'm also interested to know if caching is in the works for iOS. This is by far the best RN sound library, but I won't be able to release my app for iOS until it has offline playability (since it's a standard feature in competing apps).

@osiloke
Copy link

osiloke commented Oct 3, 2018

Cacheing is implemented in IOS by creating a local proxy server to serve the files. The proxy server would handle cacheing. I would recommend using https://github.com/swisspol/GCDWebServer

@mateomorris
Copy link

@osiloke Have you managed to enable caching with this library using that method?

@osiloke
Copy link

osiloke commented Oct 14, 2018

@mateomorris, i have. I made changes to react-native-track-player which recognizes localhost requests as local urls and therefore allows tracks to be played even though the server is offline. Take a look at the osiloke@0fb1225
I wrote a custom proxy server which rewrites segment urls in an HLS index to use the local proxy server. For example if you had a URL http://example.com/audio/example.mp3/index.m3u8 you would pass that URL to the proxy server, the proxy server will download the HLS, rewrite the segment URLS to point to that same proxy server. When the proxy server receives a request for a segment, it either downloads it or returns it from its cache.

@mateomorris
Copy link

That's pretty cool. I'll try it out and post here if I get it working. Thanks @osiloke

@aboux
Copy link

aboux commented Feb 18, 2019

Hello,
@mateomorris @thalwani did it work for you? I have a music streaming app and I might move to this library.

@gazedash
Copy link
Contributor

gazedash commented Feb 19, 2019

But what about this https://github.com/spotify/SPTPersistentCache and https://github.com/vdugnist/DVAssetLoaderDelegate ? react-native-video uses these packages to implement caching on iOS

@CapitanRedBeard
Copy link

Haven't implemented this myself but plan to in the future. For others interested here is the react-native-video discussion that @gazedash mentioned. TheWidlarzGroup/react-native-video#99

@mateomorris
Copy link

Got caching working on iOS with react-native-fetch-blob.

import RNFetchBlob from 'rn-fetch-blob'

RNFetchBlob
  .config({
    path: dirs.MainBundleDir + '/file-name.mp3',
    fileCache : true,
  })
  .fetch('GET', 'https://sample-videos.com/audio/mp3/crowd-cheering.mp3') // audio url
  .progress((received, total) => {
      console.log('progress', received / total)
  })
  .then((res) => {
    let track = {
        id: "835f65f11b6f4532873df1684680558c",
        url: 'file://' + res.path(), 
        title: 'Title',
        artist: 'Artist',
        album: 'Album',
        genre: 'Genre',
        date: 1551334620000, // RFC 3339
        artwork: 'https://previews.123rf.com/images/aquir/aquir1311/aquir131100316/23569861-sample-grunge-red-round-stamp.jpg', 
    }
    TrackPlayer.add([track]).then(function() {
      TrackPlayer.play()
    }).catch((error) => {
        console.log(error)
    })
  })
  .catch((error) => {
    console.log('Could not download file', error)
  })

@gazedash
Copy link
Contributor

gazedash commented Mar 1, 2019

@mateomorris it's not caching, it's downloading. The main point of caching is to be able to save the audio file while the user is listening to it. In your solution, user have to wait to be able to play it locally.
Or even download it twice. Just think about large audio files, how long will it take to download it?

@mateomorris
Copy link

Ah, gotcha. Didn't know that difference. At any rate, this was good enough for my purposes.

@martinezguillaume
Copy link

Any news on this issue ?

@ewindso
Copy link

ewindso commented Sep 6, 2019

Ping!

@sirakoff
Copy link

Came across https://github.com/StyleShare/HLSCachingReverseProxyServer

Can someone please help with implementing it?

@dcvz dcvz closed this as completed Aug 10, 2021
@ithustle
Copy link
Contributor

Why this issue was closed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests