VLCLocalServerFolderListViewController.m 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. //
  2. // VLCLocalServerFolderListViewController.m
  3. // VLC for iOS
  4. //
  5. // Created by Felix Paul Kühne on 10.08.13.
  6. // Copyright (c) 2013 VideoLAN. All rights reserved.
  7. //
  8. // Refer to the COPYING file of the official project for license.
  9. //
  10. #import "VLCLocalServerFolderListViewController.h"
  11. #import "MediaServerBasicObjectParser.h"
  12. #import "MediaServer1ItemObject.h"
  13. #import "MediaServer1ContainerObject.h"
  14. #import "MediaServer1Device.h"
  15. #import "VLCLocalNetworkListCell.h"
  16. #import "VLCAppDelegate.h"
  17. #import "VLCPlaylistViewController.h"
  18. #import "UINavigationController+Theme.h"
  19. @interface VLCLocalServerFolderListViewController () <UITableViewDataSource, UITableViewDelegate>
  20. {
  21. UIBarButtonItem *_backButton;
  22. MediaServer1Device *_device;
  23. NSString *_header;
  24. NSString *_rootID;
  25. NSMutableArray *_objectList;
  26. }
  27. @end
  28. @implementation VLCLocalServerFolderListViewController
  29. - (void)loadView
  30. {
  31. _tableView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
  32. _tableView.backgroundColor = [UIColor colorWithWhite:.122 alpha:1.];
  33. _tableView.delegate = self;
  34. _tableView.dataSource = self;
  35. self.view = _tableView;
  36. }
  37. - (id)initWithDevice:(MediaServer1Device*)device header:(NSString*)header andRootID:(NSString*)rootID
  38. {
  39. self = [super init];
  40. if (self) {
  41. _device = device;
  42. _header = header;
  43. _rootID = rootID;
  44. _objectList = [[NSMutableArray alloc] init];
  45. }
  46. return self;
  47. }
  48. - (void)viewDidLoad
  49. {
  50. [super viewDidLoad];
  51. NSMutableString *outResult = [[NSMutableString alloc] init];
  52. NSMutableString *outNumberReturned = [[NSMutableString alloc] init];
  53. NSMutableString *outTotalMatches = [[NSMutableString alloc] init];
  54. NSMutableString *outUpdateID = [[NSMutableString alloc] init];
  55. [[_device contentDirectory] BrowseWithObjectID:_rootID BrowseFlag:@"BrowseDirectChildren" Filter:@"*" StartingIndex:@"0" RequestedCount:@"0" SortCriteria:@"+dc:title" OutResult:outResult OutNumberReturned:outNumberReturned OutTotalMatches:outTotalMatches OutUpdateID:outUpdateID];
  56. [_objectList removeAllObjects];
  57. NSData *didl = [outResult dataUsingEncoding:NSUTF8StringEncoding];
  58. MediaServerBasicObjectParser *parser = [[MediaServerBasicObjectParser alloc] initWithMediaObjectArray:_objectList itemsOnly:NO];
  59. [parser parseFromData:didl];
  60. self.tableView.separatorColor = [UIColor colorWithWhite:.122 alpha:1.];
  61. self.view.backgroundColor = [UIColor colorWithWhite:.122 alpha:1.];
  62. self.title = _header;
  63. }
  64. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
  65. {
  66. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
  67. return NO;
  68. return YES;
  69. }
  70. #pragma mark - Table view data source
  71. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  72. {
  73. return 1;
  74. }
  75. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  76. {
  77. return _objectList.count;
  78. }
  79. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  80. {
  81. static NSString *CellIdentifier = @"LocalNetworkCellDetail";
  82. VLCLocalNetworkListCell *cell = (VLCLocalNetworkListCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  83. if (cell == nil)
  84. cell = [VLCLocalNetworkListCell cellWithReuseIdentifier:CellIdentifier];
  85. MediaServer1BasicObject *item = _objectList[indexPath.row];
  86. if (![item isContainer]) {
  87. MediaServer1ItemObject *mediaItem = _objectList[indexPath.row];
  88. [cell setSubtitle: [NSString stringWithFormat:@"%0.2f MB", (float)([mediaItem.size intValue] / 1e6)]];
  89. [cell setIsDirectory:NO];
  90. [cell setIcon:[UIImage imageNamed:@"blank"]];
  91. } else {
  92. [cell setIsDirectory:YES];
  93. [cell setIcon:[UIImage imageNamed:@"folder"]];
  94. }
  95. [cell setTitle:[item title]];
  96. return cell;
  97. }
  98. #pragma mark - Table view delegate
  99. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  100. {
  101. cell.backgroundColor = (indexPath.row % 2 == 0)? [UIColor blackColor]: [UIColor colorWithWhite:.122 alpha:1.];
  102. }
  103. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  104. {
  105. MediaServer1BasicObject *item = _objectList[indexPath.row];
  106. if ([item isContainer]) {
  107. MediaServer1ContainerObject *container = _objectList[indexPath.row];
  108. VLCLocalServerFolderListViewController *targetViewController = [[VLCLocalServerFolderListViewController alloc] initWithDevice:_device header:[container title] andRootID:[container objectID]];
  109. [[self navigationController] pushViewController:targetViewController animated:YES];
  110. } else {
  111. MediaServer1ItemObject *item = _objectList[indexPath.row];
  112. MediaServer1ItemRes *resource = nil;
  113. NSEnumerator *e = [[item resources] objectEnumerator];
  114. NSURL *itemURL;
  115. while((resource = (MediaServer1ItemRes*)[e nextObject])){
  116. APLog(@"%@ - %d, %@, %d, %d, %d, %@ (%@)", [item title], [resource bitrate], [resource duration], [resource nrAudioChannels], [resource size], [resource durationInSeconds], [resource protocolInfo], [item uri]);
  117. itemURL = [NSURL URLWithString:[item uri]];
  118. }
  119. if (itemURL && ([itemURL.scheme isEqualToString:@"http"] || [itemURL.scheme isEqualToString:@"rtsp"] || [itemURL.scheme isEqualToString:@"rtp"] || [itemURL.scheme isEqualToString:@"mms"] || [itemURL.scheme isEqualToString:@"mmsh"])) {
  120. VLCAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
  121. UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:appDelegate.playlistViewController];
  122. [navController loadTheme];
  123. appDelegate.revealController.contentViewController = navController;
  124. [appDelegate.revealController toggleSidebar:NO duration:kGHRevealSidebarDefaultAnimationDuration];
  125. [appDelegate.playlistViewController performSelector:@selector(openMovieFromURL:) withObject:itemURL afterDelay:kGHRevealSidebarDefaultAnimationDuration];
  126. }
  127. }
  128. }
  129. @end