Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maintenance: Rework playback to use Player.Open #1215

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions XBMC Remote/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},

@{
Expand Down Expand Up @@ -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",
},

@{
Expand Down Expand Up @@ -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",
},

@[],
Expand Down Expand Up @@ -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",
},

@{
Expand Down Expand Up @@ -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",
},

@{
Expand Down Expand Up @@ -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",
},

@[],
Expand Down
157 changes: 44 additions & 113 deletions XBMC Remote/DetailViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand All @@ -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];
}
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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...")]) {
Expand All @@ -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];
}
Expand All @@ -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];
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand All @@ -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) {
Expand All @@ -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];
}
}

Expand All @@ -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;
Expand All @@ -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";
Expand All @@ -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;
}
Expand All @@ -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) {
Expand Down
Loading