VLCNowPlayingInterfaceController.m 3.2 KB

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