Receiving memory warning when downloading files and playing video at the
same time
I have an app something like a media player.User can purchase video items
and play single or multiple items.
I download files with this code :
NSMutableURLRequest* rq = [[APIClient sharedClient]
requestWithMethod:@"GET" path:[[self item] downloadUrl] parameters:nil];
[rq setTimeoutInterval:5000];
_downloadOperation = [[AFHTTPRequestOperation alloc]
initWithRequest:rq] ;
_downloadOperation.outputStream = [NSOutputStream
outputStreamToFileAtPath:[[self item] localUrl] append:NO];
[_downloadOperation
setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id
responseObject) {
NSLog(@"Successfully downloaded file to %@", [_item localUrl]);
success();
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
errorBlock(error);
}];
__weak typeof(self) weakSelf = self;
[_downloadOperation setDownloadProgressBlock:^(NSUInteger bytesRead,
long long totalBytesRead, long long totalBytesExpectedToRead) {
float progress = totalBytesRead / (float)totalBytesExpectedToRead;
weakSelf.progressOverlayView.progress = progress;
}];
[_downloadOperation
setShouldExecuteAsBackgroundTaskWithExpirationHandler:^{
}];
[[APIClient sharedClient]
enqueueHTTPRequestOperation:_downloadOperation];
Nearly 10 items are in the download queue.
When 2-3 of items are downloaded, I open the custom media player
(AVPlayerQueue)
-(VideoPlayerViewController*)playMoviesForItems:(NSArray*)items{
[SharedAppDelegate pauseBackgroundMusic];
playerItems = [[NSMutableArray alloc] init];
for (ShopItem* item in items) {
NSURL *url = [NSURL fileURLWithPath:item.localUrl];
AVPlayerItem *videoItem = [AVPlayerItem playerItemWithURL:url];
[playerItems addObject:videoItem];
}
currentIndex = 0;
[self initScrubberTimer];
[self playAtIndex:currentIndex];
}
After some more files are downloaded, it starts to give memory warning,
and stops working with this error:
Terminated due to Memory Pressure
Where am I wrong? What should I release from the memory?
No comments:
Post a Comment