VIMediaDownloader.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //
  2. // VIMediaDownloader.h
  3. // VIMediaCacheDemo
  4. //
  5. // Created by Vito on 4/21/16.
  6. // Copyright © 2016 Vito. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. @protocol VIMediaDownloaderDelegate;
  10. @class VIContentInfo;
  11. @class VIMediaCacheWorker;
  12. @interface VIMediaDownloaderStatus : NSObject
  13. + (instancetype)shared;
  14. - (void)addURL:(NSURL *)url;
  15. - (void)removeURL:(NSURL *)url;
  16. /**
  17. return YES if downloading the url source
  18. */
  19. - (BOOL)containsURL:(NSURL *)url;
  20. - (NSSet *)urls;
  21. @end
  22. @interface VIMediaDownloader : NSObject
  23. - (instancetype)initWithURL:(NSURL *)url cacheWorker:(VIMediaCacheWorker *)cacheWorker;
  24. @property (nonatomic, strong, readonly) NSURL *url;
  25. @property (nonatomic, weak) id<VIMediaDownloaderDelegate> delegate;
  26. @property (nonatomic, strong) VIContentInfo *info;
  27. @property (nonatomic, assign) BOOL saveToCache;
  28. - (void)downloadTaskFromOffset:(unsigned long long)fromOffset
  29. length:(NSUInteger)length
  30. toEnd:(BOOL)toEnd;
  31. - (void)downloadFromStartToEnd;
  32. - (void)cancel;
  33. @end
  34. @protocol VIMediaDownloaderDelegate <NSObject>
  35. @optional
  36. - (void)mediaDownloader:(VIMediaDownloader *)downloader didReceiveResponse:(NSURLResponse *)response;
  37. - (void)mediaDownloader:(VIMediaDownloader *)downloader didReceiveData:(NSData *)data;
  38. - (void)mediaDownloader:(VIMediaDownloader *)downloader didFinishedWithError:(NSError *)error;
  39. @end