VLCNowPlayingInterfaceController.m 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(requestNowPlayingInfo) name:@"nowPlayingInfoUpdate" object:nil];
  31. [self requestNowPlayingInfo];
  32. }
  33. - (void)didDeactivate {
  34. // This method is called when watch view controller is no longer visible
  35. [super didDeactivate];
  36. [[NSNotificationCenter defaultCenter] removeObserver:self name:@"nowPlayingInfoUpdate" object:nil];
  37. }
  38. - (void)requestNowPlayingInfo {
  39. [WKInterfaceController openParentApplication:@{@"name": @"getNowPlayingInfo"} reply:^(NSDictionary *replyInfo, NSError *error) {
  40. [self updateWithNowPlayingInfo:replyInfo];
  41. NSLog(@"nowplayingInfo: %@",replyInfo);
  42. }];
  43. }
  44. - (void)updateWithNowPlayingInfo:(NSDictionary*)nowPlayingInfo {
  45. self.titleString = nowPlayingInfo[MPMediaItemPropertyTitle];
  46. self.playBackDurationNumber = nowPlayingInfo[MPMediaItemPropertyPlaybackDuration];
  47. }
  48. - (IBAction)playPausePressed {
  49. [WKInterfaceController openParentApplication:@{@"name": @"playpause"} reply:^(NSDictionary *replyInfo, NSError *error) {
  50. NSLog(@"playpause %@",replyInfo);
  51. }];
  52. }
  53. - (IBAction)skipForward {
  54. [WKInterfaceController openParentApplication:@{@"name": @"skipForward"} reply:^(NSDictionary *replyInfo, NSError *error) {
  55. NSLog(@"skipForward %@",replyInfo);
  56. }];
  57. }
  58. - (IBAction)skipBackward {
  59. [WKInterfaceController openParentApplication:@{@"name": @"skipBackward"} reply:^(NSDictionary *replyInfo, NSError *error) {
  60. NSLog(@"skipBackward %@",replyInfo);
  61. }];
  62. }
  63. - (void)setTitleString:(NSString *)titleString {
  64. if (![_titleString isEqualToString:titleString] || (_titleString==nil && titleString)) {
  65. _titleString = [titleString copy];
  66. self.titleLabel.text = titleString;
  67. }
  68. }
  69. - (void)setPlayBackDurationNumber:(NSNumber *)playBackDurationNumber {
  70. if (![_playBackDurationNumber isEqualToNumber:playBackDurationNumber] || (_playBackDurationNumber==nil && playBackDurationNumber)) {
  71. _playBackDurationNumber = playBackDurationNumber;
  72. float duratioFloat = playBackDurationNumber.floatValue;
  73. NSNumber *durationNumber = nil;
  74. if (duratioFloat>0.0) {
  75. durationNumber = @(playBackDurationNumber.floatValue*1000);
  76. }
  77. self.durationLabel.text = [VLCTime timeWithNumber:durationNumber].stringValue;
  78. }
  79. }
  80. @end