VLCOpenNetworkStreamTVViewController.m 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 @"Open Network Stream";
  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/404.mp4"];
  39. }
  40. [self.previouslyPlayedStreamsTableView reloadData];
  41. self.noURLsToShowLabel.hidden = _recentURLs.count != 0;
  42. }
  43. - (void)ubiquitousKeyValueStoreDidChange:(NSNotification *)notification
  44. {
  45. /* TODO: don't blindly trust that the Cloud knows best */
  46. _recentURLs = [NSMutableArray arrayWithArray:[[NSUbiquitousKeyValueStore defaultStore] arrayForKey:kVLCRecentURLs]];
  47. [self.previouslyPlayedStreamsTableView reloadData];
  48. self.noURLsToShowLabel.hidden = _recentURLs.count != 0;
  49. }
  50. - (void)viewWillDisappear:(BOOL)animated
  51. {
  52. [super viewWillDisappear:animated];
  53. /* force update before we leave */
  54. [[NSUbiquitousKeyValueStore defaultStore] synchronize];
  55. }
  56. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  57. {
  58. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RecentlyPlayedURLsTableViewCell"];
  59. if (!cell) {
  60. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"RecentlyPlayedURLsTableViewCell"];
  61. }
  62. NSString *content = _recentURLs[indexPath.row];
  63. cell.textLabel.text = [content lastPathComponent];
  64. cell.detailTextLabel.text = content;
  65. return cell;
  66. }
  67. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  68. {
  69. [self.previouslyPlayedStreamsTableView deselectRowAtIndexPath:indexPath animated:NO];
  70. [self _openURLStringAndDismiss:_recentURLs[indexPath.row]];
  71. }
  72. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  73. {
  74. return _recentURLs.count;
  75. }
  76. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  77. {
  78. return 1;
  79. }
  80. - (void)URLEnteredInField:(id)sender
  81. {
  82. [self _openURLStringAndDismiss:self.playURLField.text];
  83. }
  84. - (void)_openURLStringAndDismiss:(NSString *)url
  85. {
  86. [VLCPlayerDisplayController sharedInstance].displayMode = VLCPlayerDisplayControllerDisplayModeFullscreen;
  87. VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
  88. [vpc playURL:[NSURL URLWithString:url] subtitlesFilePath:nil];
  89. }
  90. @end