123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- /*****************************************************************************
- * VLCNowPlayingInterfaceController.m
- * VLC for iOS
- *****************************************************************************
- * Copyright (c) 2015 VideoLAN. All rights reserved.
- * $Id$
- *
- * Authors: Tobias Conradi <videolan # tobias-conradi.de>
- *
- * Refer to the COPYING file of the official project for license.
- *****************************************************************************/
- #import "VLCNowPlayingInterfaceController.h"
- #import <MediaPlayer/MediaPlayer.h>
- #import <MobileVLCKit/VLCTime.h>
- #import "VLCNotificationRelay.h"
- @interface VLCNowPlayingInterfaceController ()
- @property (nonatomic, copy) NSString *titleString;
- @property (nonatomic, copy) NSNumber *playBackDurationNumber;
- @end
- @implementation VLCNowPlayingInterfaceController
- - (void)awakeWithContext:(id)context {
- [super awakeWithContext:context];
- // Configure interface objects here.
- [self requestNowPlayingInfo];
- [[VLCNotificationRelay sharedRelay] addRelayRemoteName:@"org.videolan.ios-app.nowPlayingInfoUpdate" toLocalName:@"nowPlayingInfoUpdate"];
- }
- - (void)willActivate {
- // This method is called when watch view controller is about to be visible to user
- [super willActivate];
- [self setTitle:NSLocalizedString(@"PLAYING", nil)];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(requestNowPlayingInfo) name:@"nowPlayingInfoUpdate" object:nil];
- [self requestNowPlayingInfo];
- }
- - (void)didDeactivate {
- // This method is called when watch view controller is no longer visible
- [super didDeactivate];
- [[NSNotificationCenter defaultCenter] removeObserver:self name:@"nowPlayingInfoUpdate" object:nil];
- }
- - (void)requestNowPlayingInfo {
- [WKInterfaceController openParentApplication:@{@"name": @"getNowPlayingInfo"} reply:^(NSDictionary *replyInfo, NSError *error) {
- [self updateWithNowPlayingInfo:replyInfo];
- NSLog(@"nowplayingInfo: %@",replyInfo);
- }];
- }
- - (void)updateWithNowPlayingInfo:(NSDictionary*)nowPlayingInfo {
- self.titleString = nowPlayingInfo[MPMediaItemPropertyTitle];
- self.playBackDurationNumber = nowPlayingInfo[MPMediaItemPropertyPlaybackDuration];
- }
- - (IBAction)playPausePressed {
- [WKInterfaceController openParentApplication:@{@"name": @"playpause"} reply:^(NSDictionary *replyInfo, NSError *error) {
- NSLog(@"playpause %@",replyInfo);
- }];
- }
- - (IBAction)skipForward {
- [WKInterfaceController openParentApplication:@{@"name": @"skipForward"} reply:^(NSDictionary *replyInfo, NSError *error) {
- NSLog(@"skipForward %@",replyInfo);
- }];
- }
- - (IBAction)skipBackward {
- [WKInterfaceController openParentApplication:@{@"name": @"skipBackward"} reply:^(NSDictionary *replyInfo, NSError *error) {
- NSLog(@"skipBackward %@",replyInfo);
- }];
- }
- - (void)setTitleString:(NSString *)titleString {
- if (![_titleString isEqualToString:titleString] || (_titleString==nil && titleString)) {
- _titleString = [titleString copy];
- self.titleLabel.text = titleString;
- }
- }
- - (void)setPlayBackDurationNumber:(NSNumber *)playBackDurationNumber {
- if (![_playBackDurationNumber isEqualToNumber:playBackDurationNumber] || (_playBackDurationNumber==nil && playBackDurationNumber)) {
- _playBackDurationNumber = playBackDurationNumber;
- float duratioFloat = playBackDurationNumber.floatValue;
- NSNumber *durationNumber = nil;
- if (duratioFloat>0.0) {
- durationNumber = @(playBackDurationNumber.floatValue*1000);
- }
- self.durationLabel.text = [VLCTime timeWithNumber:durationNumber].stringValue;
- }
- }
- @end
|