diff --git a/src/detection/media/media_apple.m b/src/detection/media/media_apple.m index 6db70d048..39b0c932a 100644 --- a/src/detection/media/media_apple.m +++ b/src/detection/media/media_apple.m @@ -32,18 +32,27 @@ static const char* getMedia(FFMediaResult* result) }); dispatch_group_enter(group); + __block const char* error = NULL; MRMediaRemoteGetNowPlayingInfo(queue, ^(_Nullable CFDictionaryRef info) { - if(info != nil) { - ffCfDictGetString(info, CFSTR("kMRMediaRemoteNowPlayingInfoTitle"), &result->song); - ffCfDictGetString(info, CFSTR("kMRMediaRemoteNowPlayingInfoArtist"), &result->artist); - ffCfDictGetString(info, CFSTR("kMRMediaRemoteNowPlayingInfoAlbum"), &result->album); + if(info != nil) + { + error = ffCfDictGetString(info, CFSTR("kMRMediaRemoteNowPlayingInfoTitle"), &result->song); + if(!error) + { + ffCfDictGetString(info, CFSTR("kMRMediaRemoteNowPlayingInfoArtist"), &result->artist); + ffCfDictGetString(info, CFSTR("kMRMediaRemoteNowPlayingInfoAlbum"), &result->album); + } } + else + error = "MRMediaRemoteGetNowPlayingInfo() failed"; + dispatch_group_leave(group); }); dispatch_group_enter(group); MRMediaRemoteGetNowPlayingClient(queue, ^(_Nullable id clientObj) { - if (clientObj != nil) { + if (clientObj != nil) + { CFStringRef identifier = MRNowPlayingClientGetBundleIdentifier(clientObj); if (identifier == nil) identifier = MRNowPlayingClientGetParentAppBundleIdentifier(clientObj); @@ -65,7 +74,7 @@ static const char* getMedia(FFMediaResult* result) if(result->song.length > 0) return NULL; - return "MediaRemote failed"; + return error; } void ffDetectMediaImpl(const FFinstance* instance, FFMediaResult* media) diff --git a/src/util/apple/cf_helpers.c b/src/util/apple/cf_helpers.c index 32acc486c..65dcd7248 100644 --- a/src/util/apple/cf_helpers.c +++ b/src/util/apple/cf_helpers.c @@ -6,7 +6,11 @@ const char* ffCfStrGetString(CFStringRef str, FFstrbuf* result) //CFString stores UTF16 characters, therefore may require larger buffer to convert to UTF8 string ffStrbufEnsureFree(result, length * 2); if(!CFStringGetCString(str, result->chars, result->allocated, kCFStringEncodingUTF8)) - return "CFStringGetCString() failed"; + { + ffStrbufEnsureFree(result, length * 4); + if(!CFStringGetCString(str, result->chars, result->allocated, kCFStringEncodingUTF8)) + return "CFStringGetCString() failed"; + } // CFStringGetCString ensures the buffer is NUL terminated // https://developer.apple.com/documentation/corefoundation/1542721-cfstringgetcstring result->length = (uint32_t) strnlen(result->chars, (uint32_t)result->allocated);