diff --git a/XBMC Remote/AppDelegate.m b/XBMC Remote/AppDelegate.m index 64ef22ceb..1e54b0a92 100644 --- a/XBMC Remote/AppDelegate.m +++ b/XBMC Remote/AppDelegate.m @@ -4494,9 +4494,10 @@ - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(N @"row6": @"channelid", @"playlistid": @PLAYERID_VIDEO, @"row8": @"channelid", - @"row9": @"isrecording", - @"row10": @"channelnumber", - @"row11": @"type", + @"row9": @"channelid", + @"row10": @"isrecording", + @"row11": @"channelnumber", + @"row12": @"type", }, @{ @@ -4673,13 +4674,14 @@ - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(N @"row6": @"broadcastid", @"playlistid": @PLAYERID_VIDEO, @"row8": @"broadcastid", - @"row9": @"plotoutline", + @"row9": @"broadcastid", @"row10": @"starttime", @"row11": @"endtime", @"row12": @"progresspercentage", @"row13": @"isactive", @"row14": @"title", @"row15": @"hastimer", + @"row16": @"plotoutline", }, @{ @@ -4777,13 +4779,14 @@ - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(N @"row6": @"broadcastid", @"playlistid": @PLAYERID_VIDEO, @"row8": @"broadcastid", - @"row9": @"plotoutline", + @"row9": @"broadcastid", @"row10": @"starttime", @"row11": @"endtime", @"row12": @"progresspercentage", @"row13": @"isactive", @"row14": @"title", @"row15": @"hastimer", + @"row16": @"plotoutline", }, @[], @@ -5045,9 +5048,10 @@ - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(N @"row6": @"channelid", @"playlistid": @PLAYERID_VIDEO, @"row8": @"channelid", - @"row9": @"isrecording", - @"row10": @"channelnumber", - @"row11": @"type", + @"row9": @"channelid", + @"row10": @"isrecording", + @"row11": @"channelnumber", + @"row12": @"type", }, @{ @@ -5224,13 +5228,14 @@ - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(N @"row6": @"broadcastid", @"playlistid": @PLAYERID_VIDEO, @"row8": @"broadcastid", - @"row9": @"plotoutline", + @"row9": @"broadcastid", @"row10": @"starttime", @"row11": @"endtime", @"row12": @"progresspercentage", @"row13": @"isactive", @"row14": @"title", @"row15": @"hastimer", + @"row16": @"plotoutline", }, @{ @@ -5328,13 +5333,14 @@ - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(N @"row6": @"broadcastid", @"playlistid": @PLAYERID_VIDEO, @"row8": @"broadcastid", - @"row9": @"plotoutline", + @"row9": @"broadcastid", @"row10": @"starttime", @"row11": @"endtime", @"row12": @"progresspercentage", @"row13": @"isactive", @"row14": @"title", @"row15": @"hastimer", + @"row16": @"plotoutline", }, @[], diff --git a/XBMC Remote/DetailViewController.m b/XBMC Remote/DetailViewController.m index eaf695ea5..a30f4f678 100644 --- a/XBMC Remote/DetailViewController.m +++ b/XBMC Remote/DetailViewController.m @@ -1500,7 +1500,7 @@ - (void)viewChild:(NSIndexPath*)indexPath item:(NSDictionary*)item displayPoint: [self showActionSheet:indexPath sheetActions:sheetActions item:item rectOriginX:rectOriginX rectOriginY:rectOriginY]; } else { - [self addPlayback:item indexPath:indexPath position:indexPath.row shuffle:NO]; + [self startPlayback:item indexPath:indexPath shuffle:NO]; } return; } @@ -1594,7 +1594,7 @@ - (void)didSelectItemAtIndexPath:(NSIndexPath*)indexPath item:(NSDictionary*)ite // Selected favourite item is a media type -> play it else if ([item[@"type"] isEqualToString:@"media"]) { if (item[@"path"]) { - [self playerOpen:@{@"item": @{@"file": item[@"path"]}} index:nil]; + [self playerOpen:@{@"item": @{@"file": item[@"path"]}} index:indexPath]; } } // Selected favourite item is an unknown type -> throw an error @@ -1619,7 +1619,7 @@ - (void)didSelectItemAtIndexPath:(NSIndexPath*)indexPath item:(NSDictionary*)ite [self showActionSheet:indexPath sheetActions:sheetActions item:item rectOriginX:rectOriginX rectOriginY:rectOriginY]; } else { - [self addPlayback:item indexPath:indexPath position:indexPath.row shuffle:NO]; + [self startPlayback:item indexPath:indexPath shuffle:NO]; } } } @@ -3243,7 +3243,7 @@ - (void)showActionSheet:(NSIndexPath*)indexPath sheetActions:(NSArray*)sheetActi [self showActionSheetOptions:title options:sheetActions recording:isRecording origin:sheetOrigin fromcontroller:showFromCtrl fromview:self.view]; } else if (indexPath != nil) { // No actions found, revert back to standard play action - [self addPlayback:item indexPath:indexPath position:indexPath.row shuffle:NO]; + [self startPlayback:item indexPath:indexPath shuffle:NO]; forceMusicAlbumMode = NO; } } @@ -3523,8 +3523,7 @@ - (void)actionSheetHandler:(NSString*)actiontitle origin:(CGPoint)origin fromcon [self startSlideshow:item indexPath:selectedIndexPath]; } else { - NSInteger playFromPosition = albumView ? selectedIndexPath.row : 0; - [self addPlayback:item indexPath:selectedIndexPath position:playFromPosition shuffle:NO]; + [self startPlayback:item indexPath:selectedIndexPath shuffle:NO]; } } else if ([actiontitle isEqualToString:LOCALIZED_STR(@"Play using...")]) { @@ -3543,7 +3542,7 @@ - (void)actionSheetHandler:(NSString*)actiontitle origin:(CGPoint)origin fromcon for (NSString *actiontitle in sheetActions) { UIAlertAction *action = [UIAlertAction actionWithTitle:actiontitle style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { - [self addPlayback:item indexPath:selectedIndexPath using:actiontitle shuffle:NO]; + [self startPlayback:item indexPath:selectedIndexPath using:actiontitle shuffle:NO]; }]; [actionView addAction:action]; } @@ -3567,7 +3566,7 @@ - (void)actionSheetHandler:(NSString*)actiontitle origin:(CGPoint)origin fromcon [self deleteTimer:item indexPath:selectedIndexPath]; } else if ([actiontitle isEqualToString:LOCALIZED_STR(@"Play in shuffle mode")]) { - [self addPlayback:item indexPath:selectedIndexPath position:0 shuffle:YES]; + [self startPlayback:item indexPath:selectedIndexPath shuffle:YES]; } else if ([actiontitle isEqualToString:LOCALIZED_STR(@"Queue")]) { [self addQueue:item indexPath:selectedIndexPath]; @@ -4197,7 +4196,7 @@ - (void)addQueue:(NSDictionary*)item indexPath:(NSIndexPath*)indexPath afterCurr forceMusicAlbumMode = NO; } int playlistid = [mainFields[@"playlistid"] intValue]; - id playlistItems = [self buildPlaylistItems:playlistid item:item key:mainFields[@"row9"]]; + id playlistItems = [self buildPlaylistItems:item key:mainFields[@"row9"]]; if (!playlistItems) { [cellActivityIndicator stopAnimating]; return; @@ -4262,10 +4261,10 @@ - (void)addToPlaylist:(NSDictionary*)playlistParams indicator:(UIActivityIndicat - (void)playerOpen:(NSDictionary*)params index:(NSIndexPath*)indexPath { UIActivityIndicatorView *cellActivityIndicator = [self getCellActivityIndicator:indexPath]; - [self playerOpen:params index:indexPath indicator:cellActivityIndicator]; + [self playerOpen:params indicator:cellActivityIndicator]; } -- (void)playerOpen:(NSDictionary*)params index:(NSIndexPath*)indexPath indicator:(UIActivityIndicatorView*)cellActivityIndicator { +- (void)playerOpen:(NSDictionary*)params indicator:(UIActivityIndicatorView*)cellActivityIndicator { [cellActivityIndicator startAnimating]; [[Utilities getJsonRPC] callMethod:@"Player.Open" withParameters:params onCompletion:^(NSString *methodName, NSInteger callId, id methodResult, DSJSONRPCError *methodError, NSError *error) { [cellActivityIndicator stopAnimating]; @@ -4280,15 +4279,11 @@ - (void)playerOpen:(NSDictionary*)params index:(NSIndexPath*)indexPath indicator }]; } -- (void)addPlayback:(NSDictionary*)item indexPath:(NSIndexPath*)indexPath using:(NSString*)playername shuffle:(BOOL)shuffled { - [self addPlayback:item indexPath:indexPath using:playername position:0 shuffle:shuffled]; +- (void)startPlayback:(NSDictionary*)item indexPath:(NSIndexPath*)indexPath shuffle:(BOOL)shuffled { + [self startPlayback:item indexPath:indexPath using:nil shuffle:shuffled]; } -- (void)addPlayback:(NSDictionary*)item indexPath:(NSIndexPath*)indexPath position:(NSInteger)pos shuffle:(BOOL)shuffled { - [self addPlayback:item indexPath:indexPath using:nil position:pos shuffle:shuffled]; -} - -- (void)addPlayback:(NSDictionary*)item indexPath:(NSIndexPath*)indexPath using:(NSString*)playername position:(NSInteger)pos shuffle:(BOOL)shuffled { +- (void)startPlayback:(NSDictionary*)item indexPath:(NSIndexPath*)indexPath using:(NSString*)playername shuffle:(BOOL)shuffled { mainMenu *menuItem = [self getMainMenu:item]; NSDictionary *mainFields = menuItem.mainFields[choosedTab]; if (forceMusicAlbumMode) { @@ -4300,86 +4295,34 @@ - (void)addPlayback:(NSDictionary*)item indexPath:(NSIndexPath*)indexPath using: } UIActivityIndicatorView *cellActivityIndicator = [self getCellActivityIndicator:indexPath]; [cellActivityIndicator startAnimating]; - int playlistid = [mainFields[@"playlistid"] intValue]; - if ([mainFields[@"row8"] isEqualToString:@"channelid"] || - [mainFields[@"row8"] isEqualToString:@"broadcastid"]) { - NSNumber *channelid = item[mainFields[@"row8"]]; - if ([mainFields[@"row8"] isEqualToString:@"broadcastid"]) { - channelid = item[@"pvrExtraInfo"][@"channelid"]; - } - NSDictionary *itemParams = @{ - @"item": [NSDictionary dictionaryWithObjectsAndKeys: channelid, @"channelid", nil], - }; - [self playerOpen:itemParams index:indexPath indicator:cellActivityIndicator]; + id optionsKey; + id optionsValue; + if (AppDelegate.instance.serverVersion > 11) { + optionsKey = @"options"; + optionsValue = [NSDictionary dictionaryWithObjectsAndKeys: + @(shuffled), @"shuffled", + playername, @"playername", + nil]; } - else if ([mainFields[@"row7"] isEqualToString:@"plugin"]) { - NSDictionary *itemParams = @{ - @"item": [NSDictionary dictionaryWithObjectsAndKeys: item[@"file"], @"file", nil], - }; - [self playerOpen:itemParams index:indexPath indicator:cellActivityIndicator]; + id playlistItems = [self buildPlaylistItems:item key:mainFields[@"row9"]]; + if (!playlistItems) { + [cellActivityIndicator stopAnimating]; + return; } - else if (playername.length) { - NSString *key = mainFields[@"row8"]; - id value = item[key]; - if ([item[@"filetype"] isEqualToString:@"directory"]) { - key = @"directory"; - } - if (!value || !key) { - return; - } - NSDictionary *itemParams = @{ - @"item": @{key: value}, - @"options": @{ - @"playername": playername, - @"shuffled": @(shuffled), - }, - }; - [self playerOpen:itemParams index:indexPath indicator:cellActivityIndicator]; + NSDictionary *playbackParams = [NSDictionary dictionaryWithObjectsAndKeys: + playlistItems, @"item", + optionsValue, optionsKey, + nil]; + if (shuffled && AppDelegate.instance.serverVersion > 11) { + [[Utilities getJsonRPC] + callMethod:@"Player.SetPartymode" + withParameters:@{@"playerid": @(0), @"partymode": @NO} + onCompletion:^(NSString *methodName, NSInteger callId, id methodResult, DSJSONRPCError *methodError, NSError *internalError) { + [self playerOpen:playbackParams indicator:cellActivityIndicator]; + }]; } else { - id optionsParam = nil; - id optionsValue = nil; - if (AppDelegate.instance.serverVersion > 11) { - optionsParam = @"options"; - optionsValue = @{@"shuffled": @(shuffled)}; - } - [[Utilities getJsonRPC] callMethod:@"Playlist.Clear" withParameters:@{@"playlistid": @(playlistid)} onCompletion:^(NSString *methodName, NSInteger callId, id methodResult, DSJSONRPCError *methodError, NSError *error) { - if (error == nil && methodError == nil) { - id playlistItems = [self buildPlaylistItems:playlistid item:item key:mainFields[@"row8"]]; - if (!playlistItems) { - [cellActivityIndicator stopAnimating]; - return; - } - NSDictionary *playlistParams = @{ - @"playlistid": @(playlistid), - @"item": playlistItems, - }; - NSDictionary *playbackParams = [NSDictionary dictionaryWithObjectsAndKeys: - @{@"playlistid": @(playlistid), @"position": @(pos)}, @"item", - optionsValue, optionsParam, - nil]; - if (shuffled && AppDelegate.instance.serverVersion > 11) { - [[Utilities getJsonRPC] - callMethod:@"Player.SetPartymode" - withParameters:@{@"playerid": @(0), @"partymode": @NO} - onCompletion:^(NSString *methodName, NSInteger callId, id methodResult, DSJSONRPCError *methodError, NSError *internalError) { - [self playlistAndPlay:playlistParams - playbackParams:playbackParams - indexPath:indexPath - indicator:cellActivityIndicator]; - }]; - } - else { - [self playlistAndPlay:playlistParams - playbackParams:playbackParams - indexPath:indexPath - indicator:cellActivityIndicator]; - } - } - else { - [cellActivityIndicator stopAnimating]; - } - }]; + [self playerOpen:playbackParams indicator:cellActivityIndicator]; } } @@ -4397,11 +4340,6 @@ - (void)startSlideshow:(NSDictionary*)item indexPath:(NSIndexPath*)indexPath { if ([item[@"filetype"] isEqualToString:@"directory"]) { key = @"directory"; } - // If Playlist.Insert and Playlist.Add for recordingid is not supported, use file path. - else if (![VersionCheck hasRecordingIdPlaylistSupport] && [mainFields[@"row8"] isEqualToString:@"recordingid"]) { - key = @"file"; - value = item[@"file"]; - } if (!value || !key) { [cellActivityIndicator stopAnimating]; return; @@ -4421,10 +4359,10 @@ - (void)startSlideshow:(NSDictionary*)item indexPath:(NSIndexPath*)indexPath { } }; } - [self playerOpen:playbackParams index:nil indicator:cellActivityIndicator]; + [self playerOpen:playbackParams indicator:cellActivityIndicator]; } -- (id)buildPlaylistItems:(int)playlistid item:(NSDictionary*)item key:(id)key { +- (id)buildPlaylistItems:(NSDictionary*)item key:(id)key { id value = item[key]; if ([item[@"filetype"] isEqualToString:@"directory"]) { key = @"directory"; @@ -4449,6 +4387,11 @@ - (id)buildPlaylistItems:(int)playlistid item:(NSDictionary*)item key:(id)key { key = @"file"; value = item[@"file"]; } + else if ([key isEqualToString:@"channelid"] || + [key isEqualToString:@"broadcastid"]) { + key = @"channelid"; + value = item[@"pvrExtraInfo"][@"channelid"] ?: item[@"channelid"]; + } if (!value || !key) { return nil; } @@ -4467,18 +4410,6 @@ - (id)buildPlaylistItems:(int)playlistid item:(NSDictionary*)item key:(id)key { return playlistItems; } -- (void)playlistAndPlay:(NSDictionary*)playlistParams playbackParams:(NSDictionary*)playbackParams indexPath:(NSIndexPath*)indexPath indicator:(UIActivityIndicatorView*)cellActivityIndicator { - [[Utilities getJsonRPC] callMethod:@"Playlist.Add" withParameters:playlistParams onCompletion:^(NSString *methodName, NSInteger callId, id methodResult, DSJSONRPCError *methodError, NSError *error) { - if (error == nil && methodError == nil) { - [[NSNotificationCenter defaultCenter] postNotificationName: @"XBMCPlaylistHasChanged" object: nil]; - [self playerOpen:playbackParams index:indexPath indicator:cellActivityIndicator]; - } - else { - [cellActivityIndicator stopAnimating]; - } - }]; -} - - (void)SimpleAction:(NSString*)action params:(NSDictionary*)parameters success:(NSString*)successMessage failure:(NSString*)failureMessage { [[Utilities getJsonRPC] callMethod:action withParameters:parameters onCompletion:^(NSString *methodName, NSInteger callId, id methodResult, DSJSONRPCError *methodError, NSError *error) { if (error == nil && methodError == nil) { diff --git a/XBMC Remote/ShowInfoViewController.m b/XBMC Remote/ShowInfoViewController.m index 0aba1ee87..935938ef3 100644 --- a/XBMC Remote/ShowInfoViewController.m +++ b/XBMC Remote/ShowInfoViewController.m @@ -410,14 +410,14 @@ - (void)actionSheetHandler:(NSString*)actiontitle { [self addQueueAfterCurrent:NO]; } else if ([actiontitle isEqualToString:LOCALIZED_STR(@"Play")]) { - [self addPlayback:0.0]; + [self startPlayback:NO]; } else if ([actiontitle isEqualToString:LOCALIZED_STR(@"Record")] || [actiontitle isEqualToString:LOCALIZED_STR(@"Stop Recording")]) { [self recordChannel]; } else if ([actiontitle rangeOfString:LOCALIZED_STR(@"Resume from")].location != NSNotFound) { - [self resumePlayback]; + [self startPlayback:YES]; } else if ([actiontitle isEqualToString:LOCALIZED_STR(@"Play Trailer")]) { NSDictionary *itemParams = @{ @@ -1720,44 +1720,7 @@ - (void)addQueueAfterCurrent:(BOOL)afterCurrent { } } -- (void)resumePlayback { - NSDictionary *item = self.detailItem; - if ([item[@"family"] isEqualToString:@"broadcastid"]) { - NSDictionary *itemParams = @{ - @"item": [NSDictionary dictionaryWithObjectsAndKeys: item[@"pvrExtraInfo"][@"channelid"], @"channelid", nil], - }; - [self openFile:itemParams]; - } - else { - self.navigationItem.rightBarButtonItem.enabled = NO; - [activityIndicatorView startAnimating]; - NSString *key = item[@"family"]; - id value = item[key]; - if (!value || !key) { - [activityIndicatorView stopAnimating]; - return; - } - NSDictionary *params = @{ - @"item": @{ - key: value, - }, - @"options": @{ - @"resume": @YES, - }, - }; - [[Utilities getJsonRPC] callMethod:@"Player.Open" withParameters:params onCompletion:^(NSString *methodName, NSInteger callId, id methodResult, DSJSONRPCError *methodError, NSError *error) { - if (error == nil && methodError == nil) { - [[NSNotificationCenter defaultCenter] postNotificationName: @"XBMCPlaylistHasChanged" object: nil]; - [self showNowPlaying]; - [Utilities checkForReviewRequest]; - } - [activityIndicatorView stopAnimating]; - self.navigationItem.rightBarButtonItem.enabled = YES; - }]; - } -} - -- (void)addPlayback:(float)resumePointLocal { +- (void)startPlayback:(BOOL)resume { NSDictionary *item = self.detailItem; if ([item[@"family"] isEqualToString:@"broadcastid"]) { NSDictionary *itemParams = @{ @@ -1768,60 +1731,31 @@ - (void)addPlayback:(float)resumePointLocal { else { self.navigationItem.rightBarButtonItem.enabled = NO; [activityIndicatorView startAnimating]; - int playlistid = [item[@"playlistid"] intValue]; - [[Utilities getJsonRPC] callMethod:@"Playlist.Clear" withParameters:@{@"playlistid": @(playlistid)} onCompletion:^(NSString *methodName, NSInteger callId, id methodResult, DSJSONRPCError *methodError, NSError *error) { + NSString *key = item[@"family"]; + id value = item[key]; + if (!value || !key) { + [activityIndicatorView stopAnimating]; + return; + } + NSDictionary *params = @{ + @"item": @{ + key: value, + }, + @"options": @{ + @"resume": @(resume), + }, + }; + [[Utilities getJsonRPC] callMethod:@"Player.Open" withParameters:params onCompletion:^(NSString *methodName, NSInteger callId, id methodResult, DSJSONRPCError *methodError, NSError *error) { if (error == nil && methodError == nil) { - NSString *key = item[@"family"]; - id value = item[key]; - // If Playlist.Insert and Playlist.Add for recordingid is not supported, use file path. - if (![VersionCheck hasRecordingIdPlaylistSupport] && [item[@"family"] isEqualToString:@"recordingid"]) { - key = @"file"; - value = item[@"file"]; - } - if (!value || !key) { - [activityIndicatorView stopAnimating]; - return; - } - NSDictionary *params = @{ - @"playlistid": @(playlistid), - @"item": @{key: value}, - }; - [[Utilities getJsonRPC] callMethod:@"Playlist.Add" withParameters:params onCompletion:^(NSString *methodName, NSInteger callId, id methodResult, DSJSONRPCError *methodError, NSError *error) { - if (error == nil && methodError == nil) { - [[NSNotificationCenter defaultCenter] postNotificationName: @"XBMCPlaylistHasChanged" object: nil]; - NSDictionary *params = @{ - @"item": @{ - @"playlistid": @(playlistid), - @"position": @(0), - }, - }; - [[Utilities getJsonRPC] callMethod:@"Player.Open" withParameters:params onCompletion:^(NSString *methodName, NSInteger callId, id methodResult, DSJSONRPCError *methodError, NSError *error) { - if (error == nil && methodError == nil) { - [[NSNotificationCenter defaultCenter] postNotificationName: @"XBMCPlaylistHasChanged" object: nil]; - [activityIndicatorView stopAnimating]; - [self showNowPlaying]; - [Utilities checkForReviewRequest]; - if (resumePointLocal) { - [NSThread sleepForTimeInterval:1.0]; - [self SimpleAction:@"Player.Seek" params:[Utilities buildPlayerSeekPercentageParams:playlistid percentage:resumePointLocal]]; - } - } - else { - [activityIndicatorView stopAnimating]; - self.navigationItem.rightBarButtonItem.enabled = YES; - } - }]; - } - else { - [activityIndicatorView stopAnimating]; - self.navigationItem.rightBarButtonItem.enabled = YES; - } - }]; + [[NSNotificationCenter defaultCenter] postNotificationName: @"XBMCPlaylistHasChanged" object: nil]; + [activityIndicatorView stopAnimating]; + [self showNowPlaying]; + [Utilities checkForReviewRequest]; } else { [activityIndicatorView stopAnimating]; - self.navigationItem.rightBarButtonItem.enabled = YES; } + self.navigationItem.rightBarButtonItem.enabled = YES; }]; } }