Skip to content

Commit

Permalink
Merge pull request #122 from kjpolaszek/master
Browse files Browse the repository at this point in the history
Prevent freeze app on streaming
  • Loading branch information
saiday authored Jul 28, 2016
2 parents 4945c26 + 17d68ba commit 662e7d4
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions HysteriaPlayer/HysteriaPlayer.m
Original file line number Diff line number Diff line change
Expand Up @@ -305,19 +305,28 @@ - (void)getSourceURLAtIndex:(NSInteger)index preBuffer:(BOOL)preBuffer

- (void)setupPlayerItemWithUrl:(NSURL *)url index:(NSInteger)index
{
AVPlayerItem *item = [AVPlayerItem playerItemWithURL:url];
if (!item)
return;
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:url options:nil];
NSArray *keys = @[@"playable"];

dispatch_async(dispatch_get_main_queue(), ^{
[self setHysteriaIndex:item key:[NSNumber numberWithInteger:index]];
if (self.isMemoryCached) {
NSMutableArray *playerItems = [NSMutableArray arrayWithArray:self.playerItems];
[playerItems addObject:item];
self.playerItems = playerItems;
}
[self insertPlayerItem:item];
});
AVPlayerItem *item = [AVPlayerItem playerItemWithAsset:asset];

[asset loadValuesAsynchronouslyForKeys:keys completionHandler:^() {

dispatch_async(dispatch_get_main_queue(), ^{

[self setHysteriaIndex:item key:[NSNumber numberWithInteger:index]];

if (self.isMemoryCached) {
NSMutableArray *playerItems = [NSMutableArray arrayWithArray:self.playerItems];
[playerItems addObject:item];
self.playerItems = playerItems;
}

if ([self getLastItemIndex] == index) {
[self insertPlayerItem:item];
}
});
}];
}


Expand Down

0 comments on commit 662e7d4

Please sign in to comment.