Cleaned up repeat one/all code.

CQTexperiment
vspader 2008-02-19 23:49:51 +00:00
parent 402b403794
commit 76594c1062
2 changed files with 15 additions and 43 deletions

View File

@ -485,21 +485,7 @@
- (void)audioPlayer:(AudioPlayer *)player requestNextStream:(id)userInfo - (void)audioPlayer:(AudioPlayer *)player requestNextStream:(id)userInfo
{ {
PlaylistEntry *curEntry = (PlaylistEntry *)userInfo; PlaylistEntry *curEntry = (PlaylistEntry *)userInfo;
PlaylistEntry *pe; PlaylistEntry *pe = [playlistController getNextEntry:curEntry];
if ([playlistController repeat] == RepeatOne)
pe = curEntry;
else if ([playlistController repeat] == RepeatAll)
{
if ([[curEntry index] intValue] == [[playlistController arrangedObjects] count] - 1)
if ([playlistController shuffle] == YES)
pe = [playlistController shuffledEntryAtIndex:0];
else
pe = [playlistController entryAtIndex:0];
}
else
pe = [playlistController getNextEntry:curEntry];
[player setNextStream:[pe url] withUserInfo:pe]; [player setNextStream:[pe url] withUserInfo:pe];
} }

View File

@ -328,14 +328,14 @@
{ {
if (i < 0) if (i < 0)
{ {
if (repeat == YES) if (repeat == RepeatAll)
i += [[self arrangedObjects] count]; i += [[self arrangedObjects] count];
else else
return nil; return nil;
} }
else if (i >= [[self arrangedObjects] count]) else if (i >= [[self arrangedObjects] count])
{ {
if (repeat == YES) if (repeat == RepeatAll)
i -= [[self arrangedObjects] count]; i -= [[self arrangedObjects] count];
else else
return nil; return nil;
@ -348,7 +348,7 @@
{ {
while (i < 0) while (i < 0)
{ {
if (repeat == YES) if (repeat == RepeatAll)
{ {
[self addShuffledListToFront]; [self addShuffledListToFront];
//change i appropriately //change i appropriately
@ -361,7 +361,7 @@
} }
while (i >= [shuffleList count]) while (i >= [shuffleList count])
{ {
if (repeat == YES) if (repeat == RepeatAll)
{ {
[self addShuffledListToBack]; [self addShuffledListToBack];
} }
@ -376,6 +376,10 @@
- (PlaylistEntry *)getNextEntry:(PlaylistEntry *)pe - (PlaylistEntry *)getNextEntry:(PlaylistEntry *)pe
{ {
if (repeat == RepeatOne) {
return pe;
}
if (shuffle == YES) if (shuffle == YES)
{ {
return [self shuffledEntryAtIndex:([[pe shuffleIndex] intValue] + 1)]; return [self shuffledEntryAtIndex:([[pe shuffleIndex] intValue] + 1)];
@ -398,6 +402,10 @@
- (PlaylistEntry *)getPrevEntry:(PlaylistEntry *)pe - (PlaylistEntry *)getPrevEntry:(PlaylistEntry *)pe
{ {
if (repeat == RepeatOne) {
return pe;
}
if (shuffle == YES) if (shuffle == YES)
{ {
return [self shuffledEntryAtIndex:([[pe shuffleIndex] intValue] - 1)]; return [self shuffledEntryAtIndex:([[pe shuffleIndex] intValue] - 1)];
@ -422,23 +430,10 @@
{ {
PlaylistEntry *pe; PlaylistEntry *pe;
if (repeat == RepeatOne)
return NO;
pe = [self getNextEntry:[self currentEntry]]; pe = [self getNextEntry:[self currentEntry]];
/* needs to reshuffle playlist for added greatness */
if (pe == nil) if (pe == nil)
{ return NO;
// we are at end of shuffle list, and repeat all is requested
if (repeat == RepeatAll)
if (shuffle == YES)
pe = [self shuffledEntryAtIndex:0];
else
pe = [self entryAtIndex:0];
else
return NO;
}
[self setCurrentEntry:pe]; [self setCurrentEntry:pe];
@ -449,18 +444,9 @@
{ {
PlaylistEntry *pe; PlaylistEntry *pe;
if (repeat == RepeatOne)
return NO;
pe = [self getPrevEntry:[self currentEntry]]; pe = [self getPrevEntry:[self currentEntry]];
if (pe == nil) if (pe == nil)
{ return NO;
// we are at end of shuffle list, and repeat all is requested
if ((shuffle = YES) && (repeat == RepeatAll))
pe = [self shuffledEntryAtIndex:[shuffleList count]-1];
else
return NO;
}
[self setCurrentEntry:pe]; [self setCurrentEntry:pe];