InterfaceController.m 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. //
  2. // InterfaceController.m
  3. // VLC for iOS WatchKit Extension
  4. //
  5. // Created by Carola Nitz on 22/03/15.
  6. // Copyright (c) 2015 VideoLAN. All rights reserved.
  7. //
  8. #import "InterfaceController.h"
  9. #import <MediaLibraryKit/MediaLibraryKit.h>
  10. #import "VLCRowController.h"
  11. #import <MobileVLCKit/VLCTime.h>
  12. static NSString *const rowType = @"mediaRow";
  13. @interface InterfaceController()
  14. @property (nonatomic, strong) NSMutableArray *mediaObjects;
  15. @end
  16. @implementation InterfaceController
  17. - (void)awakeWithContext:(id)context {
  18. [super awakeWithContext:context];
  19. NSLog(@"%s",__PRETTY_FUNCTION__);
  20. NSURL *groupURL = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:@"group.org.videolan.vlc-ios"];
  21. MLMediaLibrary *mediaLibrary = [MLMediaLibrary sharedMediaLibrary];
  22. mediaLibrary.libraryBasePath = groupURL.path;
  23. self.title = NSLocalizedString(@"LIBRARY_MUSIC", nil);
  24. self.mediaObjects = [self mediaArray];
  25. [self.table setNumberOfRows:self.mediaObjects.count withRowType:rowType];
  26. [self configureTable:self.table withObjects:self.mediaObjects];
  27. }
  28. - (void)willActivate {
  29. // This method is called when watch view controller is about to be visible to user
  30. [super willActivate];
  31. NSLog(@"%s",__PRETTY_FUNCTION__);
  32. }
  33. - (void)didDeactivate {
  34. // This method is called when watch view controller is no longer visible
  35. [super didDeactivate];
  36. NSLog(@"%s",__PRETTY_FUNCTION__);
  37. }
  38. - (void)configureTable:(WKInterfaceTable *)table withObjects:(NSArray *)objects {
  39. [objects enumerateObjectsUsingBlock:^(MLFile *obj, NSUInteger idx, BOOL *stop) {
  40. VLCRowController *row = [table rowControllerAtIndex:idx];
  41. row.titleLabel.text = obj.title;
  42. row.durationLabel.text = [VLCTime timeWithNumber:obj.duration].stringValue,
  43. [row.group setBackgroundImage:obj.computedThumbnail];
  44. }];
  45. }
  46. - (NSMutableArray *)mediaArray {
  47. NSMutableArray *objects = [NSMutableArray array];
  48. // /* add all albums */
  49. // NSArray *rawAlbums = [MLAlbum allAlbums];
  50. // for (MLAlbum *album in rawAlbums) {
  51. // if (album.name.length > 0 && album.tracks.count > 1)
  52. // [objects addObject:album];
  53. // }
  54. //
  55. // /* add all shows */
  56. // NSArray *rawShows = [MLShow allShows];
  57. // for (MLShow *show in rawShows) {
  58. // if (show.name.length > 0 && show.episodes.count > 1)
  59. // [objects addObject:show];
  60. // }
  61. //
  62. // /* add all folders*/
  63. // NSArray *allFolders = [MLLabel allLabels];
  64. // for (MLLabel *folder in allFolders)
  65. // [objects addObject:folder];
  66. /* add all remaining files */
  67. NSArray *allFiles = [MLFile allFiles];
  68. for (MLFile *file in allFiles) {
  69. if (file.labels.count > 0) continue;
  70. if (!file.isShowEpisode && !file.isAlbumTrack)
  71. [objects addObject:file];
  72. else if (file.isShowEpisode) {
  73. if (file.showEpisode.show.episodes.count < 2)
  74. [objects addObject:file];
  75. } else if (file.isAlbumTrack) {
  76. if (file.albumTrack.album.tracks.count < 2)
  77. [objects addObject:file];
  78. }
  79. }
  80. return objects;
  81. }
  82. @end