New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
VLCMediaList: removeMediaAt (closes #182) #34
Conversation
- Returns NSUInteger instead of NSInteger - Returns NSNotFound if media is not found
Sources/VLCMediaList.m
Outdated
{ | ||
VLCMedia *target = [_mediaObjects objectAtIndex:index]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
objectAtIndex
checks if the provided index is in range
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will lead to an out-of-bounds exception and early application termination by the runtime if the index is not in range. Please add sanity checks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally think this is the desirable behavior for the end user. I had a hard time debugging things when removeMediaAtIndex
function wasn't critically failing even when an invalid index was passed to it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, the library shouldn't crash due to a potentially inconsistent state.
Headers/Public/VLCMediaList.h
Outdated
* \note this function silently fails if the list is read-only | ||
*/ | ||
- (void)removeMediaAtIndex:(NSUInteger)index; | ||
- (VLCMedia *)removeMediaAtIndex:(NSUInteger)index; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replicates Swift STL's func remove(at: Int) -> T
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why you want to return a VLCMedia instance that is gone from the list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Swift STL's remove(at:)
behaves the same way and if the function doesn't returns void
, how do I easily tell if a media had been deleted or not? A way to do is to raise NSRangeException, which leads to the use of indexOf
without sanity checks in the function. Sorry if I'm not making sense 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considering BOOL as a return value to expose the successful deletion. This matches typical AppKit behavior.
a129215
to
d2eaa5b
Compare
@@ -217,11 +217,6 @@ - (void)insertObject:(VLCMedia *)object inMediaAtIndex:(NSUInteger)i | |||
[self insertMedia:object atIndex:i]; | |||
} | |||
|
|||
- (void)removeObjectFromMediaAtIndex:(NSUInteger)i |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like it's not being used anywhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct.
Sources/VLCMediaList.m
Outdated
{ | ||
VLCMedia *target = [_mediaObjects objectAtIndex:index]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will lead to an out-of-bounds exception and early application termination by the runtime if the index is not in range. Please add sanity checks.
Headers/Public/VLCMediaList.h
Outdated
* \note this function silently fails if the list is read-only | ||
*/ | ||
- (void)removeMediaAtIndex:(NSUInteger)index; | ||
- (VLCMedia *)removeMediaAtIndex:(NSUInteger)index; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why you want to return a VLCMedia instance that is gone from the list.
@@ -217,11 +217,6 @@ - (void)insertObject:(VLCMedia *)object inMediaAtIndex:(NSUInteger)i | |||
[self insertMedia:object atIndex:i]; | |||
} | |||
|
|||
- (void)removeObjectFromMediaAtIndex:(NSUInteger)i |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct.
Sources/VLCMediaList.m
Outdated
}); | ||
[self didChange:NSKeyValueChangeRemoval valuesAtIndexes:[NSIndexSet indexSetWithIndex:[index intValue]] forKey:@"media"]; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you remove support for key-value coding here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I forgot to ask you about this. I personally didn't know you could do this until I saw the code for it. So, is this a feature that is used by users when they already have Notifications and delegates they can check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a used feature throughout multiple places of VLCKit, notably VLCMedia and VLCMediaPlayer. Especially the VLC-iOS app uses it.
Sources/VLCMediaList.m
Outdated
if (index >= [_mediaObjects count]) | ||
return; | ||
//remove from cached Media | ||
// Remove from cached Media |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, why do you remove the sanity check here? This is not a fail-safe operation.
d2eaa5b
to
1ae63ef
Compare
Headers/Public/VLCMediaList.h
Outdated
@@ -104,12 +104,13 @@ extern NSString *const VLCMediaListItemDeleted; | |||
- (void)insertMedia:(VLCMedia *)media atIndex:(NSUInteger)index; | |||
|
|||
/** | |||
* remove a media from a given position | |||
* remove and return the boolean result of the operation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove media at position index and return true if the operation was successful. An unsuccessful operation occurs when the index is greater than the medialists count
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well said 👍
- (BOOL)isEqual:(id)other | ||
{ | ||
return ([other isKindOfClass: [VLCMedia class]] && | ||
[other libVLCMediaDescriptor] == p_md); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
{ | ||
NSInteger result = libvlc_media_list_index_of_item(p_mlist, [media libVLCMediaDescriptor]); | ||
return result; | ||
return [_mediaObjects indexOfObject:media]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do all these changes to indexOfMedia and removeMediaAtIndex work with discovered media in a network as well? Being in a WLAN with a NAS or twonky server for example should be enough to test these changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so. There is no reason why it shouldn't. And not really sure how to test
Being in a WLAN with a NAS or twonky server
😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can try it for 30 days :) https://twonky.com/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and then you set it up build vlc ios with the custom vlckit and just check as it discovers files that all files are discovered and that it doesn't crash somewhere unexpected and when you delete one out of the discovered folder that it all works as expected
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just confirmed it still works and found a bug while at it :D
Sources/VLCMediaList.m
Outdated
{ | ||
NSNumber *index = arguments[0][@"index"]; | ||
VLCMedia *deleted = arguments[0][@"media"]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you use .first or firstobject instead of [0]?
1ae63ef
to
14c309c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks really good!
Reference https://code.videolan.org/videolan/VLCKit/issues/182