Skip to content
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

Closed
wants to merge 4 commits into from

Conversation

mkchoi212
Copy link
Contributor

- Returns NSUInteger instead of NSInteger
- Returns NSNotFound if media is not found
{
VLCMedia *target = [_mediaObjects objectAtIndex:index];
Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

* \note this function silently fails if the list is read-only
*/
- (void)removeMediaAtIndex:(NSUInteger)index;
- (VLCMedia *)removeMediaAtIndex:(NSUInteger)index;
Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor Author

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 😅

Copy link
Contributor

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.

@@ -217,11 +217,6 @@ - (void)insertObject:(VLCMedia *)object inMediaAtIndex:(NSUInteger)i
[self insertMedia:object atIndex:i];
}

- (void)removeObjectFromMediaAtIndex:(NSUInteger)i
Copy link
Contributor Author

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct.

@mkchoi212 mkchoi212 mentioned this pull request Aug 1, 2018
@fkuehne fkuehne self-requested a review August 1, 2018 12:22
{
VLCMedia *target = [_mediaObjects objectAtIndex:index];
Copy link
Contributor

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.

* \note this function silently fails if the list is read-only
*/
- (void)removeMediaAtIndex:(NSUInteger)index;
- (VLCMedia *)removeMediaAtIndex:(NSUInteger)index;
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct.

});
[self didChange:NSKeyValueChangeRemoval valuesAtIndexes:[NSIndexSet indexSetWithIndex:[index intValue]] forKey:@"media"];


Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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.

if (index >= [_mediaObjects count])
return;
//remove from cached Media
// Remove from cached Media
Copy link
Contributor

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.

@@ -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
Copy link
Member

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

Copy link
Contributor Author

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);
Copy link
Member

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];
Copy link
Member

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

Copy link
Contributor Author

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

😅

Copy link
Member

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/

Copy link
Member

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

Copy link
Contributor Author

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

{
NSNumber *index = arguments[0][@"index"];
VLCMedia *deleted = arguments[0][@"media"];
Copy link
Member

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]?

Copy link
Member

@carolanitz carolanitz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks really good!

@carolanitz
Copy link
Member

this was merged with 005bcd7 & 759bad2 & 0735d2b & 6413080

@carolanitz carolanitz closed this Aug 23, 2018
@mkchoi212 mkchoi212 deleted the medialist-fix branch August 23, 2018 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants