From 4735e5d6d3dfa2de928b94ec591d83325dd8e4aa Mon Sep 17 00:00:00 2001
From: Hank Anderson <ataganak@gmail.com>
Date: Wed, 18 May 2022 22:13:31 +0900
Subject: [PATCH] VLCMedia: add a function to get the value of 'filestat'

---
 Headers/Public/VLCMedia.h | 28 ++++++++++++++++++++++++++++
 Sources/VLCMedia.m        |  8 ++++++++
 2 files changed, 36 insertions(+)

diff --git a/Headers/Public/VLCMedia.h b/Headers/Public/VLCMedia.h
index d76ccf87..58082704 100644
--- a/Headers/Public/VLCMedia.h
+++ b/Headers/Public/VLCMedia.h
@@ -270,6 +270,34 @@ typedef NS_ENUM(unsigned, VLCMediaParsedStatus)
  */
 @property (NS_NONATOMIC_IOSONLY, readonly, copy) NSArray<VLCMediaTracksInformation *> *tracksInformation;
 
+/**
+ * list of possible libvlc_media_filestat type.
+ */
+typedef NS_ENUM(unsigned, VLCMediaFileStatType) {
+    VLCMediaFileStatTypeMtime   = 0,
+    VLCMediaFileStatTypeSize    = 1
+} NS_SWIFT_NAME(VLCMedia.FileStatType);
+
+/**
+ * list of possible libvlc_media_filestat return type.
+ */
+typedef NS_ENUM(int, VLCMediaFileStatReturnType) {
+    VLCMediaFileStatReturnTypeError     = -1,
+    VLCMediaFileStatReturnTypeNotFound  = 0,
+    VLCMediaFileStatReturnTypeSuccess   = 1
+} NS_SWIFT_NAME(VLCMedia.FileStatReturnType);
+
+/**
+ * Get a 'filestat' value
+ *
+ * 'stat' values are currently only parsed by directory accesses. This mean that only sub medias of a directory media,
+ * parsed with libvlc_media_parse_with_options() can have valid 'stat' properties.
+ * \param type VLCMediaFileStatType
+ * \param value field in which the value will be stored
+ * \return VLCMediaFileStatReturnType
+ */
+- (VLCMediaFileStatReturnType)fileStatValueForType:(const VLCMediaFileStatType)type value:(uint64_t *)value;
+
 /**
  * enum of available options for use with parseWithOptions
  * \note you may pipe multiple values for the single parameter
diff --git a/Sources/VLCMedia.m b/Sources/VLCMedia.m
index 7faa1324..63151b3e 100644
--- a/Sources/VLCMedia.m
+++ b/Sources/VLCMedia.m
@@ -405,6 +405,14 @@ static void HandleMediaParsedChanged(const libvlc_event_t * event, void * self)
 #endif
 }
 
+- (VLCMediaFileStatReturnType)fileStatValueForType:(const VLCMediaFileStatType)type value:(uint64_t *)value
+{
+    if (!p_md || !value)
+        return VLCMediaFileStatReturnTypeError;
+    
+    return libvlc_media_get_filestat(p_md, type, value);
+}
+
 - (nullable NSDictionary *)stats
 {
     if (!p_md)
-- 
GitLab