Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 41 additions & 4 deletions Headers/Public/VLCMLMedia.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -82,7 +86,6 @@ typedef NS_ENUM(UInt32, VLCMLMetadataType) {

@interface VLCMLMedia : NSObject <VLCMLObject>

@property (nonatomic, assign) float progress;
@property (nonatomic, assign) BOOL isNew;
@property (nonatomic, assign) SInt64 audioTrackIndex;
@property (nonatomic, assign) SInt64 subtitleTrackIndex;
Expand All @@ -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;

/**
Expand Down
16 changes: 16 additions & 0 deletions Headers/Public/VLCMediaLibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,22 @@ NS_SWIFT_NAME(setupMediaLibrary(databasePath:medialibraryPath:));
- (nullable NSArray<VLCMLMedia *> *)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<VLCMLMedia *> *)inProgressMediaOfType:(VLCMLMediaType)type
NS_SWIFT_NAME(inProgressMedia(type:));
- (nullable NSArray<VLCMLMedia *> *)inProgressMediaOfType:(VLCMLMediaType)type
sortingCriteria:(VLCMLSortingCriteria)criteria
desc:(BOOL)desc
NS_SWIFT_NAME(inProgressMedia(type:sortingCriteria:desc:));

#pragma mark - Media groups

/**
Expand Down
16 changes: 3 additions & 13 deletions Sources/VLCMLMedia.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -159,11 +154,6 @@ - (int)playCount
return _media->playCount();
}

- (BOOL)increasePlayCount
{
return _media->increasePlayCount();
}

- (BOOL)setPlayCount:(UInt32)playCount
{
return _media->setPlayCount(playCount);
Expand Down
15 changes: 15 additions & 0 deletions Sources/VLCMediaLibrary.m
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,21 @@ - (BOOL)removeExternalMedia:(VLCMLMedia *)media
return [VLCMLUtils arrayFromMediaQuery:_ml->videoFiles(&param)];
}

- (NSArray<VLCMLMedia *> *)inProgressMediaOfType:(VLCMLMediaType)type
{
return [VLCMLUtils arrayFromMediaQuery:_ml->inProgressMedia((medialibrary::IMedia::Type)type)];
}

- (NSArray<VLCMLMedia *> *)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,
&param)];
}

#pragma mark - Media groups

- (nullable VLCMLMediaGroup *)createMediaGroupWithName:(NSString *)name
Expand Down