HysteriaPlayer icon indicating copy to clipboard operation
HysteriaPlayer copied to clipboard

possible to do caching?

Open narendra-ct opened this issue 10 years ago • 7 comments

Hii, . Thanks for giving good sample and i planned to download some audios to play on offline mode , is there any possibility please help me.

Thanks, Narender

narendra-ct avatar Mar 14 '14 02:03 narendra-ct

I didn't implement that.

@jerson seems done that on his project, maybe @jerson can teach us how to do this.

saiday avatar Mar 14 '14 08:03 saiday

Hi @narendra-ct sorry it took there an example of how to implement HysteriaPlayer online and offline files in the method asyncSetupSourceGetter.


  [self.player asyncSetupSourceGetter:^(NSUInteger index) {

        NSDictionary *song = [self.playlist objectAtIndex:index];

        if ([self songExists:song]) {

            [self.player setupPlayerItemWithUrl:[self getSongUrl:song]  Order:index];
            NSLog(@"Local File");

        }else{

            NSLog(@"Remote File");

            [self getMp3Url:song onFinish:^(NSString *url) {
                [self.player setupPlayerItemWithUrl:[NSURL URLWithString:url] Order:index];


            }];

        }


    } ItemsCount:[self.playlist count]];

jerson avatar Mar 17 '14 13:03 jerson

Hi @Saiday,

can you help me on one issue :

Hysteria Player is caching very well and you did a very good job . Cached audio is playing when application is live if i quit the application at that time already played audios cache is clearing so, here is it possible to store cached audio data in documents to play already played audios with out buffering ?

Thanks, Narendra.

narendra-ct avatar Apr 05 '14 07:04 narendra-ct

@narendra-ct

I had no solutions on this topic yet, but I have a suggestion on it.

AVPlayerItem have a property playbackBufferFull, on hysteriaPlayerCurrentItemPreloaded delegate check this property if it's TRUE then save it to Document Directory.

saiday avatar Apr 08 '14 00:04 saiday

Hi saiday , do you know how to save the file to document directory? it seems we only have AVPlayerItem and the AVPlayerItem has a AVAsset property. In theory we could use AVAssetExportSession to export the AVAsset out to document directory, but like http://stackoverflow.com/questions/6259095/caching-with-avplayer-and-avassetexportsession, I always get AVAssetExportSessionStatusFailed.

windhood avatar May 05 '14 06:05 windhood

Noticed, will take a look.

Thank you.

On Monday, May 5, 2014, Wenhu [email protected] wrote:

Hi saiday , do you know how to save the file to document directory? it seems we only have AVPlayerItem and the AVPlayerItem has a AVAsset property. In theory we could use AVAssetExportSession to export the AVAsset out to document directory, but like http://stackoverflow.com/questions/6259095/caching-with-avplayer-and-avassetexportsession, I always get AVAssetExportSessionStatusFailed.

— Reply to this email directly or view it on GitHubhttps://github.com/StreetVoice/HysteriaPlayer/issues/48#issuecomment-42161679 .

saiday avatar May 05 '14 12:05 saiday

Guys, check this out: http://vombat.tumblr.com/post/86294492874/caching-audio-streamed-using-avplayer

playbackBufferFull doesn't mean the entire video is loaded, just the buffer. You'll see AVAsset's resource loader make periodic requests later to refill it as it runs low.

Wall of text here, but I just spent a week on this exact thing, and have some notes that might help.

There are a few versions of the the code above floating around. A Google search for "avassetresourceloaderdelegate cache" turns up a few. You can improve the performance with some codecs by opening a second connection that hops around and grabs specific byte ranges to fulfill resource loader requests for content far ahead of the main connection's, which is downloading the whole thing in order so you've got a NSMutableData instance you can write to file once the connection finishes. Side note, you could do some clever things and maybe have the primary connection skip sections that have already been downloaded, but then you're worrying about combining sparse data and the overhead of opening new connections.

Also, if you do this, be careful with AVQueuePlayer. AVAssets on the same player share a resource loader (the docs only mention that's the case with copies of the same asset, but it's not limited to that). AVQueuePlayer starts loading data for the next item before it's playing, so you can end up fulfilling requests for one asset with the original asset's data if you're not careful. I found it easier to have two players and swap our their player layers.

jasonbnewell avatar Feb 22 '16 03:02 jasonbnewell