From 34075e75a139cc29e6507f756240886b5f611839 Mon Sep 17 00:00:00 2001 From: Hank Anderson <ataganak@gmail.com> Date: Mon, 15 Apr 2024 06:13:07 +0900 Subject: [PATCH] VLCLibrary: Add currentErrorMessage class property --- Headers/Public/VLCLibrary.h | 10 ++++++++++ Sources/Core/VLCLibrary.m | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/Headers/Public/VLCLibrary.h b/Headers/Public/VLCLibrary.h index 1247f2af..1ea0429e 100644 --- a/Headers/Public/VLCLibrary.h +++ b/Headers/Public/VLCLibrary.h @@ -43,6 +43,16 @@ OBJC_VISIBLE @property (class, nonatomic, nullable) id<VLCEventsConfiguring> sharedEventsConfiguration; +/** + * A human-readable error message for the last LibVLC error in the calling + * thread. The resulting string is valid until another error occurs (at least + * until the next LibVLC call). + * + * @warning + * This will be NULL if there was no error. + */ +@property (class, nonatomic, copy, nullable) NSString *currentErrorMessage; + /** * Returns the library's shared instance * \return The library's shared instance diff --git a/Sources/Core/VLCLibrary.m b/Sources/Core/VLCLibrary.m index d1e5f91c..86b6b06d 100644 --- a/Sources/Core/VLCLibrary.m +++ b/Sources/Core/VLCLibrary.m @@ -104,6 +104,17 @@ static id<VLCEventsConfiguring> _sharedEventsConfiguration = nil; [self setSharedEventsConfiguration:[VLCEventsDefaultConfiguration new]]; } ++ (nullable NSString *)currentErrorMessage +{ + const char * __nullable errmsg = libvlc_errmsg(); + return errmsg ? @(errmsg) : nil; +} + ++ (void)setCurrentErrorMessage:(nullable NSString *)currentErrorMessage +{ + currentErrorMessage ? libvlc_printerr(currentErrorMessage.UTF8String) : libvlc_clearerr(); +} + + (VLCLibrary *)sharedLibrary { static dispatch_once_t onceToken; -- GitLab