Re: MLMediaLibrary sometimes does not call my KVO
___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: MLMediaLibrary sometimes does not call my KVO
> It’s very hard for a sandboxed app to get access to the internals of Photos > without using MLMediaLibrary, though not too difficult for non-sandboxed. > MLMediaLibrary was added because of this need. I was wondering whether this API (Photos Framework aka PhotoKit) would be better suited : https://developer.apple.com/reference/photos?language=objc According to the doc, it should be available on macOS 10.11+ Best regards, Gabriel. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: MLMediaLibrary sometimes does not call my KVO
> On 22 Sep 2016, at 10:45 PM, Gabriel Zachmannwrote: > >> I’ve run into some unreliability in MLMediaLibrary. It appears to be a bug >> because it sometimes can be seen in places that use MLMediaLibrary within >> general standard components, such as NSOpenPanel (this adds a media browsing >> section if it is set up to allow image types, for example). > > Thanks a lot for your insights. > > I am wondering: how does Microsoft Word , for instance, do it? > I've never seen that application behave funny when it shows the image browser > (it faithfully shows all 10,000 images from my Photos library). > > Does it use a different API? It’s very hard for a sandboxed app to get access to the internals of Photos without using MLMediaLibrary, though not too difficult for non-sandboxed. MLMediaLibrary was added because of this need. There is a standard component - NSMediaLibraryBrowserController (https://developer.apple.com/reference/appkit/nsmedialibrarybrowsercontroller?language=objc) that gives you a standardised panel for browsing. Unfortunately it’s a standalone panel rather than a view that you can embed within a larger UI, but it’s sufficient for many needs, and is easy to use. You could look at that and see if its behaviour is more reliable than your own code. I have tried it and it isn’t for me - I get the same problems with it that I see in NSOpenPanel, or when using KVO on MLMediaLibrary elements, which is why the problem seems to be in the lower-level layers of MLMediaLibrary. —Graham ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: MLMediaLibrary sometimes does not call my KVO
> I’ve run into some unreliability in MLMediaLibrary. It appears to be a bug > because it sometimes can be seen in places that use MLMediaLibrary within > general standard components, such as NSOpenPanel (this adds a media browsing > section if it is set up to allow image types, for example). Thanks a lot for your insights. I am wondering: how does Microsoft Word , for instance, do it? I've never seen that application behave funny when it shows the image browser (it faithfully shows all 10,000 images from my Photos library). Does it use a different API? Best regards, Gabriel. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: MLMediaLibrary sometimes does not call my KVO
> On 22 Sep 2016, at 8:59 AM, Gabriel Zachmannwrote: > > I am a bit at a loss about the MLMediaLibrary API. > Maybe, I haven't quite understood it yet, maybe something else is wrong. > > I am writing a screen saver that accesses Photos' albums and the images > referenced by them. > (Code excerpts follow at the end of this email.) > > I create an array of the top level albums at startup time of the screensaver > , using the KVO. > At runtime, I occasionally extract the images referenced by one of those > albums. > Most of the time it works fine, except sometimes, my KVO never gets invoked, > at which point my screensaver hangs, > because I had to stop the animation during that phase. > > I have not found a pattern as to when this happens. > (it is not a deterministic album, nor a deterministic n-th time.) > > Any suggestions, hints, insights, and pointers will be highly appreciated. I’ve run into some unreliability in MLMediaLibrary. It appears to be a bug because it sometimes can be seen in places that use MLMediaLibrary within general standard components, such as NSOpenPanel (this adds a media browsing section if it is set up to allow image types, for example). Sometimes it only shows the top level of the library, and all of the subgroups are simply missing, and never show up no matter how long you wait. Opening the panel a second time will finally deliver the subgroups. My guess is that as it’s an asynchronous API, on the first pass the system has to build a lot of internal cached state, and it may fail for any reason. On the second pass, it has already primed much of that cache and the failure doesn’t occur. While this happens quite often, it’s not every time, so I haven’t spotted an absolute pattern. But I think your code needs to be designed in such a way that if the KVO it is expecting (for the contents of a given group, say) is never delivered, it doesn’t fail. I’m not sure that is really possible for a photos screensaver (in that case you have no photos to display), but there’s no reason it needs to hang. Hopefully 10.12 will fix the issue, but I haven’t had a chance to look into that yet. —Graham ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
MLMediaLibrary sometimes does not call my KVO
I am a bit at a loss about the MLMediaLibrary API. Maybe, I haven't quite understood it yet, maybe something else is wrong. I am writing a screen saver that accesses Photos' albums and the images referenced by them. (Code excerpts follow at the end of this email.) I create an array of the top level albums at startup time of the screensaver , using the KVO. At runtime, I occasionally extract the images referenced by one of those albums. Most of the time it works fine, except sometimes, my KVO never gets invoked, at which point my screensaver hangs, because I had to stop the animation during that phase. I have not found a pattern as to when this happens. (it is not a deterministic album, nor a deterministic n-th time.) Any suggestions, hints, insights, and pointers will be highly appreciated. Best regards, Gabriel. The code snippets. (variables ending with underscore are instance variables.) This is what I do at startup time (in -initwithFrame:isPreview:) albums_ = [[NSMutableArray alloc] init]; NSDictionary *options = @{ MLMediaLoadSourceTypesKey: @(MLMediaSourceTypeImage), MLMediaLoadIncludeSourcesKey: @[MLMediaSourcePhotosIdentifier] }; mediaLibrary_ = [[MLMediaLibrary alloc] initWithOptions: options]; [mediaLibrary_ addObserver: self forKeyPath: @"mediaSources" options: 0 context: (__bridge void *) @"mediaLibraryLoaded"]; [mediaLibrary_.mediaSources objectForKey: MLMediaSourcePhotosIdentifier ]; // starts asynchronous loading During runtime, this gets executed occasionally: album_ = albums_[album_id]; [album_ addObserver: self forKeyPath: @"mediaObjects" options: 0 context: @"mediaObjects"]; [album_ mediaObjects]; I have checked using log message that addObserver: does actually get executed. And this is my key value observer: - (void) observeValueForKeyPath: (NSString *) keyPath ofObject: (id) object change: (NSDictionary *) change context: (void *) context { MLMediaSource * mediaSource = [mediaLibrary_.mediaSources objectForKey: MLMediaSourcePhotosIdentifier]; if ( context == (__bridge void *) @"mediaLibraryLoaded" ) { [mediaSource addObserver: self forKeyPath: @"rootMediaGroup" options: 0 context: (__bridge void *) @"rootMediaGroupLoaded"]; [mediaSource rootMediaGroup]; // start next phase: load groups } else if ( context == (__bridge void *) @"rootMediaGroupLoaded" ) { MLMediaGroup *albums = [mediaSource mediaGroupForIdentifier: @"TopLevelAlbums"]; for ( MLMediaGroup * album in albums.childGroups ) { NSString * albumName = [album.attributes objectForKey: @"name"]; [self logMessage: [NSString stringWithFormat: @"album name = %@", albumName] asError: NO]; if ( albumName ) [albums_ addObject: album ]; } } else if ( context == (__bridge void *) @"mediaObjects" ) { NSArray * mediaObjects = album_.mediaObjects; for ( MLMediaObject * mediaObject in mediaObjects ) { if ( mediaObject.mediaType != MLMediaTypeImage ) // we still get movies as mediaObjects, which might be contained in a Photos album continue; NSURL * url = mediaObject.URL; [photoPaths_ addObject: url.path]; } } } Again, I checked with a log message that the KVO never gets invoked in the case when the screen saver hangs (i.e., I am positive the hanging is not caused by an infinite loop or similar in the KVO.) ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com