VLCOpenNetworkStreamTVViewController.m 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*****************************************************************************
  2. * VLC for iOS
  3. *****************************************************************************
  4. * Copyright (c) 2015 VideoLAN. All rights reserved.
  5. * $Id$
  6. *
  7. * Authors: Felix Paul Kühne <fkuehne # videolan.org>
  8. *
  9. * Refer to the COPYING file of the official project for license.
  10. *****************************************************************************/
  11. #import "VLCOpenNetworkStreamTVViewController.h"
  12. #import "VLCPlaybackController.h"
  13. #import "VLCPlayerDisplayController.h"
  14. @interface VLCOpenNetworkStreamTVViewController ()
  15. {
  16. NSMutableArray *_recentURLs;
  17. }
  18. @end
  19. @implementation VLCOpenNetworkStreamTVViewController
  20. - (NSString *)title
  21. {
  22. return NSLocalizedString(@"OPEN_NETWORK", nil);
  23. }
  24. - (void)viewDidLoad {
  25. [super viewDidLoad];
  26. NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
  27. [notificationCenter addObserver:self
  28. selector:@selector(ubiquitousKeyValueStoreDidChange:)
  29. name:NSUbiquitousKeyValueStoreDidChangeExternallyNotification
  30. object:[NSUbiquitousKeyValueStore defaultStore]];
  31. /* force store update */
  32. NSUbiquitousKeyValueStore *ubiquitousKeyValueStore = [NSUbiquitousKeyValueStore defaultStore];
  33. [ubiquitousKeyValueStore synchronize];
  34. /* fetch data from cloud */
  35. _recentURLs = [NSMutableArray arrayWithArray:[[NSUbiquitousKeyValueStore defaultStore] arrayForKey:kVLCRecentURLs]];
  36. if (_recentURLs.count == 0) {
  37. [_recentURLs addObject:@"http://streams.videolan.org/streams/mp4/Mr_MrsSmith-h264_aac.mp4"];
  38. [_recentURLs addObject:@"http://streams.videolan.org/streams/mp4/Mr&MrsSmith.txt"];
  39. }
  40. [self.previouslyPlayedStreamsTableView reloadData];
  41. self.noURLsToShowLabel.hidden = _recentURLs.count != 0;
  42. self.playURLField.placeholder = NSLocalizedString(@"ENTER_URL", nil);
  43. }
  44. - (void)ubiquitousKeyValueStoreDidChange:(NSNotification *)notification
  45. {
  46. /* TODO: don't blindly trust that the Cloud knows best */
  47. _recentURLs = [NSMutableArray arrayWithArray:[[NSUbiquitousKeyValueStore defaultStore] arrayForKey:kVLCRecentURLs]];
  48. [self.previouslyPlayedStreamsTableView reloadData];
  49. self.noURLsToShowLabel.hidden = _recentURLs.count != 0;
  50. }
  51. - (void)viewWillDisappear:(BOOL)animated
  52. {
  53. [super viewWillDisappear:animated];
  54. /* force update before we leave */
  55. [[NSUbiquitousKeyValueStore defaultStore] synchronize];
  56. }
  57. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  58. {
  59. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RecentlyPlayedURLsTableViewCell"];
  60. if (!cell) {
  61. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"RecentlyPlayedURLsTableViewCell"];
  62. }
  63. NSString *content = _recentURLs[indexPath.row];
  64. cell.textLabel.text = [content lastPathComponent];
  65. cell.detailTextLabel.text = content;
  66. return cell;
  67. }
  68. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  69. {
  70. [self.previouslyPlayedStreamsTableView deselectRowAtIndexPath:indexPath animated:NO];
  71. [self _openURLStringAndDismiss:_recentURLs[indexPath.row]];
  72. }
  73. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  74. {
  75. return _recentURLs.count;
  76. }
  77. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  78. {
  79. return 1;
  80. }
  81. - (void)URLEnteredInField:(id)sender
  82. {
  83. [self _openURLStringAndDismiss:self.playURLField.text];
  84. }
  85. - (void)_openURLStringAndDismiss:(NSString *)url
  86. {
  87. [VLCPlayerDisplayController sharedInstance].displayMode = VLCPlayerDisplayControllerDisplayModeFullscreen;
  88. VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
  89. [vpc playURL:[NSURL URLWithString:url] subtitlesFilePath:nil];
  90. }
  91. @end