From a7d1853853857d8e6006f4beca3b04fb39c317b6 Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Thu, 4 Aug 2016 18:55:13 -0700 Subject: [PATCH] Support GME M3U playlists. --- Plugins/GME/GameContainer.m | 21 +++++++++++++++++++++ Plugins/GME/GameDecoder.m | 20 ++++++++++++++++++++ Plugins/GME/GameMetadataReader.m | 18 ++++++++++++++++++ 3 files changed, 59 insertions(+) diff --git a/Plugins/GME/GameContainer.m b/Plugins/GME/GameContainer.m index 40d5d942b..c21a97648 100755 --- a/Plugins/GME/GameContainer.m +++ b/Plugins/GME/GameContainer.m @@ -63,6 +63,27 @@ ALog(@"GME: Error loading file: %@ %s", [url path], error); return [NSArray arrayWithObject:url]; } + + NSURL *m3uurl = [url URLByDeletingPathExtension]; + m3uurl = [m3uurl URLByAppendingPathExtension:@"m3u"]; + if ([source open:m3uurl]) + { + if ([source seekable]) + { + [source seek:0 whence:SEEK_END]; + size = [source tell]; + [source seek:0 whence:SEEK_SET]; + + data = malloc(size); + [source read:data amount:size]; + + error = gme_load_m3u_data(emu, data, size); + free(data); + + ALog(@"M3U loaded: %s", error ? error : "no error"); + } + } + int track_count = gme_track_count(emu); NSMutableArray *tracks = [NSMutableArray array]; diff --git a/Plugins/GME/GameDecoder.m b/Plugins/GME/GameDecoder.m index c8f810547..54c6aca76 100755 --- a/Plugins/GME/GameDecoder.m +++ b/Plugins/GME/GameDecoder.m @@ -78,6 +78,26 @@ gme_err_t readCallback( void* data, void* out, long count ) return NO; } + NSURL *m3uurl = [[source url] URLByDeletingPathExtension]; + m3uurl = [m3uurl URLByAppendingPathExtension:@"m3u"]; + id audioSourceClass = NSClassFromString(@"AudioSource"); + id m3usrc = [audioSourceClass audioSourceForURL:m3uurl]; + if ([m3usrc open:m3uurl]) + { + if ([m3usrc seekable]) + { + [source seek:0 whence:SEEK_END]; + long size = [source tell]; + [source seek:0 whence:SEEK_SET]; + + void *data = malloc(size); + [source read:data amount:size]; + + gme_load_m3u_data(emu, data, size); + free(data); + } + } + int track_num = [[[source url] fragment] intValue]; //What if theres no fragment? Assuming we get 0. gme_info_t * info; diff --git a/Plugins/GME/GameMetadataReader.m b/Plugins/GME/GameMetadataReader.m index 3c8c9462f..3c68a1606 100644 --- a/Plugins/GME/GameMetadataReader.m +++ b/Plugins/GME/GameMetadataReader.m @@ -71,6 +71,24 @@ return NO; } + NSURL *m3uurl = [url URLByDeletingPathExtension]; + m3uurl = [m3uurl URLByAppendingPathExtension:@"m3u"]; + if ([source open:m3uurl]) + { + if ([source seekable]) + { + [source seek:0 whence:SEEK_END]; + long size = [source tell]; + [source seek:0 whence:SEEK_SET]; + + void *data = malloc(size); + [source read:data amount:size]; + + gme_load_m3u_data(emu, data, size); + free(data); + } + } + int track_num; if ([[url fragment] length] == 0) track_num = 0;