XML playlist now stores and loads the playback queue
This commit is contained in:
parent
7d6cfe50df
commit
8d19b2538a
3 changed files with 64 additions and 31 deletions
|
@ -227,7 +227,14 @@ NSMutableDictionary * dictionaryWithPropertiesOfObject(id obj, NSArray * filterL
|
||||||
[dict release];
|
[dict release];
|
||||||
}
|
}
|
||||||
|
|
||||||
NSDictionary * dictionary = [NSDictionary dictionaryWithObjectsAndKeys:albumArtSet, @"albumArt", topLevel, @"items", nil];
|
NSMutableArray * queueList = [[NSMutableArray alloc] init];
|
||||||
|
|
||||||
|
for (PlaylistEntry *pe in [playlistController queueList])
|
||||||
|
{
|
||||||
|
[queueList addObject:[NSNumber numberWithInt:pe.index]];
|
||||||
|
}
|
||||||
|
|
||||||
|
NSDictionary * dictionary = [NSDictionary dictionaryWithObjectsAndKeys:albumArtSet, @"albumArt", queueList, @"queue", topLevel, @"items", nil];
|
||||||
|
|
||||||
NSData * data = [NSPropertyListSerialization dataWithPropertyList:dictionary format:NSPropertyListXMLFormat_v1_0 options:0 error:0];
|
NSData * data = [NSPropertyListSerialization dataWithPropertyList:dictionary format:NSPropertyListXMLFormat_v1_0 options:0 error:0];
|
||||||
|
|
||||||
|
@ -235,6 +242,8 @@ NSMutableDictionary * dictionaryWithPropertiesOfObject(id obj, NSArray * filterL
|
||||||
|
|
||||||
[topLevel release];
|
[topLevel release];
|
||||||
|
|
||||||
|
[queueList release];
|
||||||
|
|
||||||
[fileHandle writeData:data];
|
[fileHandle writeData:data];
|
||||||
|
|
||||||
[fileHandle closeFile];
|
[fileHandle closeFile];
|
||||||
|
@ -276,7 +285,7 @@ NSMutableDictionary * dictionaryWithPropertiesOfObject(id obj, NSArray * filterL
|
||||||
NSMutableArray *containedURLs = [NSMutableArray array];
|
NSMutableArray *containedURLs = [NSMutableArray array];
|
||||||
NSMutableArray *fileURLs = [NSMutableArray array];
|
NSMutableArray *fileURLs = [NSMutableArray array];
|
||||||
NSMutableArray *validURLs = [NSMutableArray array];
|
NSMutableArray *validURLs = [NSMutableArray array];
|
||||||
NSArray *xmlURLs = nil;
|
NSDictionary *xmlData = nil;
|
||||||
|
|
||||||
if (!urls)
|
if (!urls)
|
||||||
return [NSArray array];
|
return [NSArray array];
|
||||||
|
@ -333,7 +342,7 @@ NSMutableDictionary * dictionaryWithPropertiesOfObject(id obj, NSArray * filterL
|
||||||
}
|
}
|
||||||
else if ([[[[url path] pathExtension] lowercaseString] isEqualToString:@"xml"])
|
else if ([[[[url path] pathExtension] lowercaseString] isEqualToString:@"xml"])
|
||||||
{
|
{
|
||||||
xmlURLs = [XmlContainer entriesForContainerURL:url];
|
xmlData = [XmlContainer entriesForContainerURL:url];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -378,14 +387,12 @@ NSMutableDictionary * dictionaryWithPropertiesOfObject(id obj, NSArray * filterL
|
||||||
|
|
||||||
//Create actual entries
|
//Create actual entries
|
||||||
int count = [validURLs count];
|
int count = [validURLs count];
|
||||||
if (xmlURLs) count += [xmlURLs count];
|
if (xmlData) count += [[xmlData objectForKey:@"entries"] count];
|
||||||
|
|
||||||
int i;
|
int i = 0;
|
||||||
NSMutableArray *entries = [NSMutableArray arrayWithCapacity:count];
|
NSMutableArray *entries = [NSMutableArray arrayWithCapacity:count];
|
||||||
for (i = 0; i < [validURLs count]; i++)
|
for (NSURL *url in validURLs)
|
||||||
{
|
{
|
||||||
NSURL *url = [validURLs objectAtIndex:i];
|
|
||||||
|
|
||||||
PlaylistEntry *pe;
|
PlaylistEntry *pe;
|
||||||
if ([url isFileURL])
|
if ([url isFileURL])
|
||||||
pe = [[FilePlaylistEntry alloc] init];
|
pe = [[FilePlaylistEntry alloc] init];
|
||||||
|
@ -399,12 +406,16 @@ NSMutableDictionary * dictionaryWithPropertiesOfObject(id obj, NSArray * filterL
|
||||||
[entries addObject:pe];
|
[entries addObject:pe];
|
||||||
|
|
||||||
[pe release];
|
[pe release];
|
||||||
|
|
||||||
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < [xmlURLs count]; i++)
|
int j = index + i;
|
||||||
{
|
|
||||||
NSDictionary * entry = [xmlURLs objectAtIndex:i];
|
|
||||||
|
|
||||||
|
if (xmlData)
|
||||||
|
{
|
||||||
|
for (NSDictionary *entry in [xmlData objectForKey:@"entries"])
|
||||||
|
{
|
||||||
PlaylistEntry *pe;
|
PlaylistEntry *pe;
|
||||||
if ([[entry objectForKey:@"URL"] isFileURL])
|
if ([[entry objectForKey:@"URL"] isFileURL])
|
||||||
pe = [[FilePlaylistEntry alloc] init];
|
pe = [[FilePlaylistEntry alloc] init];
|
||||||
|
@ -412,17 +423,38 @@ NSMutableDictionary * dictionaryWithPropertiesOfObject(id obj, NSArray * filterL
|
||||||
pe = [[PlaylistEntry alloc] init];
|
pe = [[PlaylistEntry alloc] init];
|
||||||
|
|
||||||
[pe setValuesForKeysWithDictionary:entry];
|
[pe setValuesForKeysWithDictionary:entry];
|
||||||
pe.index = index+i+[validURLs count];
|
pe.index = index+i;
|
||||||
pe.queuePosition = -1;
|
pe.queuePosition = -1;
|
||||||
[entries addObject:pe];
|
[entries addObject:pe];
|
||||||
|
|
||||||
[pe release];
|
[pe release];
|
||||||
|
|
||||||
|
++i;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NSIndexSet *is = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(index, [entries count])];
|
NSIndexSet *is = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(index, [entries count])];
|
||||||
|
|
||||||
[playlistController insertObjects:entries atArrangedObjectIndexes:is];
|
[playlistController insertObjects:entries atArrangedObjectIndexes:is];
|
||||||
|
|
||||||
|
if (xmlData && [[xmlData objectForKey:@"queue"] count])
|
||||||
|
{
|
||||||
|
[playlistController emptyQueueList:self];
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
for (NSNumber *index in [xmlData objectForKey:@"queue"])
|
||||||
|
{
|
||||||
|
int indexVal = [index intValue] + j;
|
||||||
|
PlaylistEntry *pe = [entries objectAtIndex:indexVal];
|
||||||
|
pe.queuePosition = i;
|
||||||
|
pe.queued = YES;
|
||||||
|
|
||||||
|
[[playlistController queueList] addObject:pe];
|
||||||
|
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//Select the first entry in the group that was just added
|
//Select the first entry in the group that was just added
|
||||||
[playlistController setSelectionIndex:index];
|
[playlistController setSelectionIndex:index];
|
||||||
[self performSelectorInBackground:@selector(loadInfoForEntries:) withObject:entries];
|
[self performSelectorInBackground:@selector(loadInfoForEntries:) withObject:entries];
|
||||||
|
|
|
@ -14,6 +14,6 @@
|
||||||
|
|
||||||
+ (NSURL *)urlForPath:(NSString *)path relativeTo:(NSString *)baseFilename;
|
+ (NSURL *)urlForPath:(NSString *)path relativeTo:(NSString *)baseFilename;
|
||||||
|
|
||||||
+ (NSArray *)entriesForContainerURL:(NSURL *)url;
|
+ (NSDictionary *)entriesForContainerURL:(NSURL *)url;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -54,7 +54,7 @@
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSArray *)entriesForContainerURL:(NSURL *)url
|
+ (NSDictionary *)entriesForContainerURL:(NSURL *)url
|
||||||
{
|
{
|
||||||
if (![url isFileURL])
|
if (![url isFileURL])
|
||||||
return [NSArray array];
|
return [NSArray array];
|
||||||
|
@ -84,12 +84,13 @@
|
||||||
|
|
||||||
NSArray * items = (isArray) ? (NSArray*)plist : [(NSDictionary *)plist objectForKey:@"items"];
|
NSArray * items = (isArray) ? (NSArray*)plist : [(NSDictionary *)plist objectForKey:@"items"];
|
||||||
|
|
||||||
NSDictionary *entry;
|
|
||||||
NSDictionary *albumArt = (isArray) ? nil : [(NSDictionary *)plist objectForKey:@"albumArt"];
|
NSDictionary *albumArt = (isArray) ? nil : [(NSDictionary *)plist objectForKey:@"albumArt"];
|
||||||
NSEnumerator *e = [items objectEnumerator];
|
|
||||||
|
NSArray *queueList = (isArray) ? [NSArray array] : [(NSDictionary *)plist objectForKey:@"queue"];
|
||||||
|
|
||||||
NSMutableArray *entries = [NSMutableArray array];
|
NSMutableArray *entries = [NSMutableArray array];
|
||||||
|
|
||||||
while ((entry = [e nextObject]))
|
for (NSDictionary *entry in items)
|
||||||
{
|
{
|
||||||
NSMutableDictionary * preparedEntry = [NSMutableDictionary dictionaryWithDictionary:entry];
|
NSMutableDictionary * preparedEntry = [NSMutableDictionary dictionaryWithDictionary:entry];
|
||||||
|
|
||||||
|
@ -101,7 +102,7 @@
|
||||||
[entries addObject:[NSDictionary dictionaryWithDictionary:preparedEntry]];
|
[entries addObject:[NSDictionary dictionaryWithDictionary:preparedEntry]];
|
||||||
}
|
}
|
||||||
|
|
||||||
return entries;
|
return [NSDictionary dictionaryWithObjectsAndKeys:entries, @"entries", queueList, @"queue", nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
Loading…
Reference in a new issue