瀏覽代碼

improve now playing play pause button state handing

Tobias Conradi 10 年之前
父節點
當前提交
a6fa0a68ca

+ 1 - 0
Sources/VLCAppDelegate.m

@@ -670,6 +670,7 @@
         responseDict = [self nowPlayingResponseDict];
     } else if ([userInfo[@"name"] isEqualToString:@"playpause"]) {
         [_movieViewController playPause];
+        responseDict = @{@"playing": @(_movieViewController.isPlaying)};
     } else if ([userInfo[@"name"] isEqualToString:@"skipForward"]) {
         [_movieViewController forward:nil];
     } else if ([userInfo[@"name"] isEqualToString:@"skipBackward"]) {

+ 2 - 0
Sources/VLCMovieViewController.h

@@ -84,6 +84,8 @@
 @property (nonatomic, strong) IBOutlet UILabel *trackNameLabel;
 @property (nonatomic, strong) IBOutlet UIImageView *artworkImageView;
 
+@property (nonatomic, readonly, getter=isPlaying) BOOL playing;
+
 - (IBAction)closePlayback:(id)sender;
 
 - (IBAction)positionSliderAction:(id)sender;

+ 6 - 0
Sources/VLCMovieViewController.m

@@ -847,6 +847,12 @@ currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom
     self.videoFilterButton.hidden = audioOnly;
 }
 
+- (BOOL)isPlaying
+{
+    return [VLCPlaybackController sharedInstance].isPlaying;
+}
+
+
 - (IBAction)playPause
 {
     LOCKCHECK;

+ 23 - 17
VLC for iOS WatchKit Extension/VLCNowPlayingInterfaceController.m

@@ -25,21 +25,13 @@
 }
 @property (nonatomic, copy) NSString *titleString;
 @property (nonatomic, copy) NSNumber *playBackDurationNumber;
-@property (nonatomic) BOOL isPlaying;
+@property (nonatomic, getter=isPlaying) BOOL playing;
 @property (nonatomic) NSTimer *updateTimer;
+@property (nonatomic, weak) MLFile *currentFile;
 @end
 
 @implementation VLCNowPlayingInterfaceController
 
-- (instancetype)init
-{
-    self = [super init];
-    if (self) {
-        _isPlaying = YES;
-    }
-    return self;
-}
-
 - (void)awakeWithContext:(id)context {
     [super awakeWithContext:context];
 
@@ -49,6 +41,8 @@
 
     [self setTitle:NSLocalizedString(@"PLAYING", nil)];
 
+    [self setPlaying:YES];
+
     [self requestNowPlayingInfo];
     [[VLCNotificationRelay sharedRelay] addRelayRemoteName:@"org.videolan.ios-app.nowPlayingInfoUpdate" toLocalName:@"nowPlayingInfoUpdate"];
 }
@@ -106,8 +100,14 @@
 
     self.playBackDurationNumber = duration;
 
-    /* do not block */
-    [self performSelectorInBackground:@selector(loadThumbnailForFile:) withObject:file];
+    NSNumber *rate = nowPlayingInfo[MPNowPlayingInfoPropertyPlaybackRate];
+    self.playing = rate.floatValue > 0.0;
+
+    if ([self.currentFile isEqual:file]) {
+        self.currentFile = file;
+        /* do not block */
+        [self performSelectorInBackground:@selector(loadThumbnailForFile:) withObject:file];
+    }
 }
 
 - (void)loadThumbnailForFile:(MLFile *)file
@@ -118,8 +118,13 @@
 }
 
 - (IBAction)playPausePressed {
-    self.isPlaying = !self.isPlaying;
     [WKInterfaceController openParentApplication:@{@"name": @"playpause"} reply:^(NSDictionary *replyInfo, NSError *error) {
+        NSNumber *playing = replyInfo[@"playing"];
+        if ([playing isKindOfClass:[NSNumber class]]) {
+            self.playing = playing.boolValue;
+        } else {
+            self.playing = !self.playing;
+        }
         if (error)
             NSLog(@"playpause failed with reply %@ error: %@",replyInfo,error);
     }];
@@ -140,10 +145,11 @@
 }
 
 
-- (void)setIsPlaying:(BOOL)isPlaying {
-
-    [self.playPauseButton setBackgroundImageNamed:isPlaying? @"pause":@"play"];
-    _isPlaying = isPlaying;
+- (void)setPlaying:(BOOL)playing {
+    if (_playing != playing) {
+        [self.playPauseButton setBackgroundImageNamed:playing? @"pause":@"play"];
+        _playing = playing;
+    }
 }
 
 - (void)setTitleString:(NSString *)titleString {