VLCNowPlayingInterfaceController.m 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*****************************************************************************
  2. * VLCNowPlayingInterfaceController.m
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2015 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Authors: Tobias Conradi <videolan # tobias-conradi.de>
  9. *
  10. * Refer to the COPYING file of the official project for license.
  11. *****************************************************************************/
  12. #import "VLCNowPlayingInterfaceController.h"
  13. #import <MediaPlayer/MediaPlayer.h>
  14. #import <MobileVLCKit/VLCTime.h>
  15. #import "VLCNotificationRelay.h"
  16. @interface VLCNowPlayingInterfaceController ()
  17. @property (nonatomic, copy) NSString *titleString;
  18. @property (nonatomic, copy) NSNumber *playBackDurationNumber;
  19. @end
  20. @implementation VLCNowPlayingInterfaceController
  21. - (void)awakeWithContext:(id)context {
  22. [super awakeWithContext:context];
  23. // Configure interface objects here.
  24. [self requestNowPlayingInfo];
  25. [[VLCNotificationRelay sharedRelay] addRelayRemoteName:@"org.videolan.ios-app.nowPlayingInfoUpdate" toLocalName:@"nowPlayingInfoUpdate"];
  26. }
  27. - (void)willActivate {
  28. // This method is called when watch view controller is about to be visible to user
  29. [super willActivate];
  30. [self setTitle:NSLocalizedString(@"PLAYING", nil)];
  31. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(requestNowPlayingInfo) name:@"nowPlayingInfoUpdate" object:nil];
  32. [self requestNowPlayingInfo];
  33. }
  34. - (void)didDeactivate {
  35. // This method is called when watch view controller is no longer visible
  36. [super didDeactivate];
  37. [[NSNotificationCenter defaultCenter] removeObserver:self name:@"nowPlayingInfoUpdate" object:nil];
  38. }
  39. - (void)requestNowPlayingInfo {
  40. [WKInterfaceController openParentApplication:@{@"name": @"getNowPlayingInfo"} reply:^(NSDictionary *replyInfo, NSError *error) {
  41. [self updateWithNowPlayingInfo:replyInfo];
  42. NSLog(@"nowplayingInfo: %@",replyInfo);
  43. }];
  44. }
  45. - (void)updateWithNowPlayingInfo:(NSDictionary*)nowPlayingInfo {
  46. self.titleString = nowPlayingInfo[MPMediaItemPropertyTitle];
  47. self.playBackDurationNumber = nowPlayingInfo[MPMediaItemPropertyPlaybackDuration];
  48. }
  49. - (IBAction)playPausePressed {
  50. [WKInterfaceController openParentApplication:@{@"name": @"playpause"} reply:^(NSDictionary *replyInfo, NSError *error) {
  51. NSLog(@"playpause %@",replyInfo);
  52. }];
  53. }
  54. - (IBAction)skipForward {
  55. [WKInterfaceController openParentApplication:@{@"name": @"skipForward"} reply:^(NSDictionary *replyInfo, NSError *error) {
  56. NSLog(@"skipForward %@",replyInfo);
  57. }];
  58. }
  59. - (IBAction)skipBackward {
  60. [WKInterfaceController openParentApplication:@{@"name": @"skipBackward"} reply:^(NSDictionary *replyInfo, NSError *error) {
  61. NSLog(@"skipBackward %@",replyInfo);
  62. }];
  63. }
  64. - (void)setTitleString:(NSString *)titleString {
  65. if (![_titleString isEqualToString:titleString] || (_titleString==nil && titleString)) {
  66. _titleString = [titleString copy];
  67. self.titleLabel.text = titleString;
  68. }
  69. }
  70. - (void)setPlayBackDurationNumber:(NSNumber *)playBackDurationNumber {
  71. if (![_playBackDurationNumber isEqualToNumber:playBackDurationNumber] || (_playBackDurationNumber==nil && playBackDurationNumber)) {
  72. _playBackDurationNumber = playBackDurationNumber;
  73. float duratioFloat = playBackDurationNumber.floatValue;
  74. NSNumber *durationNumber = nil;
  75. if (duratioFloat>0.0) {
  76. durationNumber = @(playBackDurationNumber.floatValue*1000);
  77. }
  78. self.durationLabel.text = [VLCTime timeWithNumber:durationNumber].stringValue;
  79. }
  80. }
  81. @end