Skip to content

Commit

Permalink
Fix memory cache could turned off by removeAllItems
Browse files Browse the repository at this point in the history
  • Loading branch information
saiday committed Dec 31, 2015
1 parent e3746b3 commit 145e08c
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions HysteriaPlayer/HysteriaPlayer.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ @interface HysteriaPlayer ()

- (void)longTimeBufferBackground;
- (void)longTimeBufferBackgroundCompleted;
- (void)setHysteriaIndex:(AVPlayerItem *)item Key:(NSNumber *)order;

@end

Expand Down Expand Up @@ -199,7 +198,7 @@ -(void)longTimeBufferBackgroundCompleted
#pragma mark =========== Runtime AssociatedObject =========
#pragma mark -

- (void)setHysteriaIndex:(AVPlayerItem *)item Key:(NSNumber *)order {
- (void)setHysteriaIndex:(AVPlayerItem *)item key:(NSNumber *)order {
objc_setAssociatedObject(item, Hysteriatag, order, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

Expand Down Expand Up @@ -305,7 +304,7 @@ - (void)setupPlayerItemWithUrl:(NSURL *)url index:(NSInteger)index
return;

dispatch_async(dispatch_get_main_queue(), ^{
[self setHysteriaIndex:item Key:[NSNumber numberWithInteger:index]];
[self setHysteriaIndex:item key:[NSNumber numberWithInteger:index]];
if (self.isMemoryCached) {
NSMutableArray *playerItems = [NSMutableArray arrayWithArray:self.playerItems];
[playerItems addObject:item];
Expand Down Expand Up @@ -373,7 +372,7 @@ - (void)removeAllItems
}
}

self.playerItems = nil;
self.playerItems = [self isMemoryCached] ? [NSArray array] : nil;
[self.audioPlayer removeAllItems];
}

Expand All @@ -397,7 +396,7 @@ - (void)removeItemAtIndex:(NSInteger)order
[self.audioPlayer removeItem:item];
}
} else if (checkIndex > order) {
[self setHysteriaIndex:item Key:[NSNumber numberWithInteger:checkIndex -1]];
[self setHysteriaIndex:item key:[NSNumber numberWithInteger:checkIndex -1]];
}
}
}
Expand All @@ -408,7 +407,7 @@ - (void)moveItemFromIndex:(NSInteger)from toIndex:(NSInteger)to
NSInteger checkIndex = [[self getHysteriaIndex:item] integerValue];
if (checkIndex == from || checkIndex == to) {
NSNumber *replaceOrder = checkIndex == from ? [NSNumber numberWithInteger:to] : [NSNumber numberWithInteger:from];
[self setHysteriaIndex:item Key:replaceOrder];
[self setHysteriaIndex:item key:replaceOrder];
}
}
}
Expand Down

0 comments on commit 145e08c

Please sign in to comment.