From 2d23e7ccce77ad1c7fd71cb3210961fff3272d15 Mon Sep 17 00:00:00 2001 From: Soomin Lee Date: Thu, 25 Jun 2020 10:09:57 +0200 Subject: [PATCH] WIP: Changes medialibrary MR#316 --- Headers/Public/VLCMLMedia.h | 45 +++++++++++++++++++++++++++++--- Headers/Public/VLCMediaLibrary.h | 16 ++++++++++++ Sources/VLCMLMedia.m | 16 +++--------- Sources/VLCMediaLibrary.m | 15 +++++++++++ 4 files changed, 75 insertions(+), 17 deletions(-) diff --git a/Headers/Public/VLCMLMedia.h b/Headers/Public/VLCMLMedia.h index cbe49a9..0b3cbdf 100644 --- a/Headers/Public/VLCMLMedia.h +++ b/Headers/Public/VLCMLMedia.h @@ -52,8 +52,12 @@ typedef NS_ENUM(UInt32, VLCMLMetadataType) { VLCMLMetadataTypeRating = 1, // Playback - VLCMLMetadataTypeProgress = 50, - VLCMLMetadataTypeSpeed, + /* + * Removed starting from model 27, this is now a full field in the + * media table + * VLCMLMetadataTypeProgress = 50, + */ + VLCMLMetadataTypeSpeed = 51, VLCMLMetadataTypeTitle, VLCMLMetadataTypeChapter, VLCMLMetadataTypeProgram, @@ -82,7 +86,6 @@ typedef NS_ENUM(UInt32, VLCMLMetadataType) { @interface VLCMLMedia : NSObject -@property (nonatomic, assign) float progress; @property (nonatomic, assign) BOOL isNew; @property (nonatomic, assign) SInt64 audioTrackIndex; @property (nonatomic, assign) SInt64 subtitleTrackIndex; @@ -109,7 +112,41 @@ typedef NS_ENUM(UInt32, VLCMLMetadataType) { - (BOOL)updateTitle:(NSString *)title; - (SInt64)duration; - (int)playCount; -- (BOOL)increasePlayCount; + +/** + * @brief progress Returns the media progress, in percent + * + * This is the same unit as VLC's playback position, ie. a float between + * 0 and 1. + * If the value is negative, it means the playback has either never been + * played, or it was played to completion + */ +- (float)progress; + +/** + * @brief setProgress updates the media playback progress + * + * @param progress The current media progress + * + * The media library will interpret the value to determine if the playback + * is completed and the media should be marked as watched (therefor increasing + * the playcount). If the progress isn't large enough, the media library will + * ignore the new progress. + * The base value for the beginning/end of a media is 5%, meaning that the + * first 5% will not increase the progress, and the last 5% will mark the + * media as watched and reset the progress value (so that next playback + * restarts from the beginning) + * These 5% are decreased by 1% for every playback hour, so for instance, a + * 3h movie will use 5% - (3h * 1%), so the first 2% will be ignored, the last + * 2% will trigger the completion. + * + * This returns true in case of success, false otherwise. + * Calling progress() or playCount() afterward will fetch the curated values. + * This will also bump the media last played date, causing it to appear at + * the top of the history + */ +- (BOOL)setProgress:(float)progress; + - (BOOL)setPlayCount:(UInt32)playCount; /** diff --git a/Headers/Public/VLCMediaLibrary.h b/Headers/Public/VLCMediaLibrary.h index bd40bc1..73e588d 100644 --- a/Headers/Public/VLCMediaLibrary.h +++ b/Headers/Public/VLCMediaLibrary.h @@ -293,6 +293,22 @@ NS_SWIFT_NAME(setupMediaLibrary(databasePath:medialibraryPath:)); - (nullable NSArray *)videoFilesWithSortingCriteria:(VLCMLSortingCriteria)criteria desc:(BOOL)desc; + +/** + * @brief inProgressMedia Returns media for which playback wasn't completed + * @param type The type of media to fetch, or 'Unknown' for all + * @param params Some query parameters + * @return A query representing the results set + * + * @see{VLCMLMedia::setProgress} + */ +- (nullable NSArray *)inProgressMediaOfType:(VLCMLMediaType)type +NS_SWIFT_NAME(inProgressMedia(type:)); +- (nullable NSArray *)inProgressMediaOfType:(VLCMLMediaType)type + sortingCriteria:(VLCMLSortingCriteria)criteria + desc:(BOOL)desc +NS_SWIFT_NAME(inProgressMedia(type:sortingCriteria:desc:)); + #pragma mark - Media groups /** diff --git a/Sources/VLCMLMedia.m b/Sources/VLCMLMedia.m index dd6012a..4d922d0 100644 --- a/Sources/VLCMLMedia.m +++ b/Sources/VLCMLMedia.m @@ -45,17 +45,12 @@ @implementation VLCMLMedia #pragma mark - Getters/Setters - (float)progress { - VLCMLMetadata *progressMetadata = [self metadataOfType:VLCMLMetadataTypeProgress]; - if (!progressMetadata.str || [progressMetadata.str isEqualToString:@""]) { - return 0.0; - } - - return progressMetadata.str.floatValue; + return _media->progress(); } -- (void)setProgress:(float)progress +- (BOOL)setProgress:(float)progress { - [self setMetadataOfType:VLCMLMetadataTypeProgress stringValue:[NSString stringWithFormat: @"%f", progress]]; + return _media->setProgress(progress); } - (BOOL)isNew @@ -159,11 +154,6 @@ - (int)playCount return _media->playCount(); } -- (BOOL)increasePlayCount -{ - return _media->increasePlayCount(); -} - - (BOOL)setPlayCount:(UInt32)playCount { return _media->setPlayCount(playCount); diff --git a/Sources/VLCMediaLibrary.m b/Sources/VLCMediaLibrary.m index ba4ba1b..4dfe01d 100644 --- a/Sources/VLCMediaLibrary.m +++ b/Sources/VLCMediaLibrary.m @@ -193,6 +193,21 @@ - (BOOL)removeExternalMedia:(VLCMLMedia *)media return [VLCMLUtils arrayFromMediaQuery:_ml->videoFiles(¶m)]; } +- (NSArray *)inProgressMediaOfType:(VLCMLMediaType)type +{ + return [VLCMLUtils arrayFromMediaQuery:_ml->inProgressMedia((medialibrary::IMedia::Type)type)]; +} + +- (NSArray *)inProgressMediaOfType:(VLCMLMediaType)type + sortingCriteria:(VLCMLSortingCriteria)criteria + desc:(BOOL)desc +{ + medialibrary::QueryParameters param = [VLCMLUtils queryParamatersFromSort:criteria desc:desc]; + + return [VLCMLUtils arrayFromMediaQuery:_ml->inProgressMedia((medialibrary::IMedia::Type)type, + ¶m)]; +} + #pragma mark - Media groups - (nullable VLCMLMediaGroup *)createMediaGroupWithName:(NSString *)name