[Playlist] Handle invalid files in a better way

Invalid files may include nil URLs, which should be skipped or stop
playback altogether. Invalid files will be marked as an error, and
stop playback.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
swiftingly
Christopher Snowhill 2022-06-18 16:09:41 -07:00
parent 54b102f09e
commit 1c2ecc1c7c
5 changed files with 25 additions and 3 deletions

View File

@ -187,6 +187,13 @@ NSDictionary *makeRGInfo(PlaylistEntry *pe) {
if(playbackStatus != CogStatusStopped && playbackStatus != CogStatusStopping)
[self stop:self];
if(!pe.url) {
pe.error = YES;
pe.errorMessage = NSLocalizedString(@"ErrorMessageBadFile", @"");
[[FIRCrashlytics crashlytics] log:@"Attempting to play bad file."];
return;
}
[[FIRCrashlytics crashlytics] logWithFormat:@"Playing track: %@", pe.url];
DLog(@"PLAYLIST CONTROLLER: %@", [playlistController class]);
@ -577,9 +584,14 @@ NSDictionary *makeRGInfo(PlaylistEntry *pe) {
}
}
if(pe) {
if(pe && pe.url) {
[[FIRCrashlytics crashlytics] logWithFormat:@"Beginning decoding track: %@", pe.url];
[player setNextStream:pe.url withUserInfo:pe withRGInfo:makeRGInfo(pe)];
} else if(pe) {
[[FIRCrashlytics crashlytics] log:@"Invalid playlist entry reached."];
[player setNextStream:nil];
pe.error = YES;
pe.errorMessage = NSLocalizedString(@"ErrorMessageBadFile", @"");
} else {
[[FIRCrashlytics crashlytics] log:@"End of playlist reached."];
[player setNextStream:nil];

View File

@ -484,7 +484,7 @@ NSURL *_Nullable urlForPath(NSString *_Nullable path) {
- (void)setMetadata:(NSDictionary *)metadata {
if(metadata == nil) {
self.error = YES;
self.errorMessage = @"Unable to retrieve metadata.";
self.errorMessage = NSLocalizedString(@"ErrorMetadata", @"");
} else {
self.volume = 1;
[self setValuesForKeysWithDictionary:metadata];

View File

@ -642,8 +642,12 @@ static inline void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_bloc
NSBlockOperation *op = [[NSBlockOperation alloc] init];
[op addExecutionBlock:^{
if(weakPe.deLeted) {
if(weakPe.deLeted || !weakPe.url) {
[weakLock lock];
if(!weakPe.url) {
weakPe.error = YES;
weakPe.errorMessage = NSLocalizedString(@"ErrorMessageBadFile", @"");
}
progress += progressstep;
[self setProgressJobStatus:progress];
[weakLock unlock];

View File

@ -63,3 +63,6 @@
"ProgressActionLoadingMetadata" = "loading metadata for tracks";
"ProgressSubActionLoadingMetadata" = "processing files";
"ProgressSubActionMetadataApply" = "applying info to playlist storage";
"ErrorMetadata" = "Unable to retrieve metadata.";
"ErrorMessageBadFile" = "Unable to parse metadata for bad file.";

View File

@ -63,3 +63,6 @@
"ProgressActionLoadingMetadata" = "loading metadata for tracks";
"ProgressSubActionLoadingMetadata" = "processing files";
"ProgressSubActionMetadataApply" = "applying info to playlist storage";
"ErrorMetadata" = "Unable to retrieve metadata.";
"ErrorMessageBadFile" = "Unable to parse metadata for bad file.";