Commit a6fa0a68 authored by Tobias's avatar Tobias Committed by Felix Paul Kühne

improve now playing play pause button state handing

parent 7bea7864
...@@ -670,6 +670,7 @@ ...@@ -670,6 +670,7 @@
responseDict = [self nowPlayingResponseDict]; responseDict = [self nowPlayingResponseDict];
} else if ([userInfo[@"name"] isEqualToString:@"playpause"]) { } else if ([userInfo[@"name"] isEqualToString:@"playpause"]) {
[_movieViewController playPause]; [_movieViewController playPause];
responseDict = @{@"playing": @(_movieViewController.isPlaying)};
} else if ([userInfo[@"name"] isEqualToString:@"skipForward"]) { } else if ([userInfo[@"name"] isEqualToString:@"skipForward"]) {
[_movieViewController forward:nil]; [_movieViewController forward:nil];
} else if ([userInfo[@"name"] isEqualToString:@"skipBackward"]) { } else if ([userInfo[@"name"] isEqualToString:@"skipBackward"]) {
......
...@@ -84,6 +84,8 @@ ...@@ -84,6 +84,8 @@
@property (nonatomic, strong) IBOutlet UILabel *trackNameLabel; @property (nonatomic, strong) IBOutlet UILabel *trackNameLabel;
@property (nonatomic, strong) IBOutlet UIImageView *artworkImageView; @property (nonatomic, strong) IBOutlet UIImageView *artworkImageView;
@property (nonatomic, readonly, getter=isPlaying) BOOL playing;
- (IBAction)closePlayback:(id)sender; - (IBAction)closePlayback:(id)sender;
- (IBAction)positionSliderAction:(id)sender; - (IBAction)positionSliderAction:(id)sender;
......
...@@ -847,6 +847,12 @@ currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom ...@@ -847,6 +847,12 @@ currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom
self.videoFilterButton.hidden = audioOnly; self.videoFilterButton.hidden = audioOnly;
} }
- (BOOL)isPlaying
{
return [VLCPlaybackController sharedInstance].isPlaying;
}
- (IBAction)playPause - (IBAction)playPause
{ {
LOCKCHECK; LOCKCHECK;
......
...@@ -25,21 +25,13 @@ ...@@ -25,21 +25,13 @@
} }
@property (nonatomic, copy) NSString *titleString; @property (nonatomic, copy) NSString *titleString;
@property (nonatomic, copy) NSNumber *playBackDurationNumber; @property (nonatomic, copy) NSNumber *playBackDurationNumber;
@property (nonatomic) BOOL isPlaying; @property (nonatomic, getter=isPlaying) BOOL playing;
@property (nonatomic) NSTimer *updateTimer; @property (nonatomic) NSTimer *updateTimer;
@property (nonatomic, weak) MLFile *currentFile;
@end @end
@implementation VLCNowPlayingInterfaceController @implementation VLCNowPlayingInterfaceController
- (instancetype)init
{
self = [super init];
if (self) {
_isPlaying = YES;
}
return self;
}
- (void)awakeWithContext:(id)context { - (void)awakeWithContext:(id)context {
[super awakeWithContext:context]; [super awakeWithContext:context];
...@@ -49,6 +41,8 @@ ...@@ -49,6 +41,8 @@
[self setTitle:NSLocalizedString(@"PLAYING", nil)]; [self setTitle:NSLocalizedString(@"PLAYING", nil)];
[self setPlaying:YES];
[self requestNowPlayingInfo]; [self requestNowPlayingInfo];
[[VLCNotificationRelay sharedRelay] addRelayRemoteName:@"org.videolan.ios-app.nowPlayingInfoUpdate" toLocalName:@"nowPlayingInfoUpdate"]; [[VLCNotificationRelay sharedRelay] addRelayRemoteName:@"org.videolan.ios-app.nowPlayingInfoUpdate" toLocalName:@"nowPlayingInfoUpdate"];
} }
...@@ -106,8 +100,14 @@ ...@@ -106,8 +100,14 @@
self.playBackDurationNumber = duration; self.playBackDurationNumber = duration;
/* do not block */ NSNumber *rate = nowPlayingInfo[MPNowPlayingInfoPropertyPlaybackRate];
[self performSelectorInBackground:@selector(loadThumbnailForFile:) withObject:file]; 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 - (void)loadThumbnailForFile:(MLFile *)file
...@@ -118,8 +118,13 @@ ...@@ -118,8 +118,13 @@
} }
- (IBAction)playPausePressed { - (IBAction)playPausePressed {
self.isPlaying = !self.isPlaying;
[WKInterfaceController openParentApplication:@{@"name": @"playpause"} reply:^(NSDictionary *replyInfo, NSError *error) { [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) if (error)
NSLog(@"playpause failed with reply %@ error: %@",replyInfo,error); NSLog(@"playpause failed with reply %@ error: %@",replyInfo,error);
}]; }];
...@@ -140,10 +145,11 @@ ...@@ -140,10 +145,11 @@
} }
- (void)setIsPlaying:(BOOL)isPlaying { - (void)setPlaying:(BOOL)playing {
if (_playing != playing) {
[self.playPauseButton setBackgroundImageNamed:isPlaying? @"pause":@"play"]; [self.playPauseButton setBackgroundImageNamed:playing? @"pause":@"play"];
_isPlaying = isPlaying; _playing = playing;
}
} }
- (void)setTitleString:(NSString *)titleString { - (void)setTitleString:(NSString *)titleString {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment