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

possible to do caching? #48

Open
narendra-ct opened this issue Mar 14, 2014 · 7 comments
Open

possible to do caching? #48

narendra-ct opened this issue Mar 14, 2014 · 7 comments

Comments

@narendra-ct
Copy link

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

@saiday
Copy link
Member

saiday commented Mar 14, 2014

I didn't implement that.

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

@jerson
Copy link
Contributor

jerson commented Mar 17, 2014

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]];

@narendra-ct
Copy link
Author

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.

@saiday
Copy link
Member

saiday commented Apr 8, 2014

@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.

@windhood
Copy link

windhood commented May 5, 2014

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.

@saiday
Copy link
Member

saiday commented May 5, 2014

Noticed, will take a look.

Thank you.

On Monday, May 5, 2014, Wenhu notifications@github.com 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//issues/48#issuecomment-42161679
.

@jasonbnewell
Copy link

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.

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

No branches or pull requests

5 participants