robovm icon indicating copy to clipboard operation
robovm copied to clipboard

AVAsset.loadValuesAsynchronouslyForKeys wrong method signature?

Open someguy233 opened this issue 4 years ago • 2 comments

Issue details: AVAsset.loadValuesAsynchronouslyForKeys is declared like this in Objective-C:

- (void)loadValuesAsynchronouslyForKeys:(NSArray<NSString *> *)keys 
                      completionHandler:(void (^)(void))handler;

But in RoboVM, it asks for List<AVMetadataKey> instead of List<NSString>.

I need to pass strings such as this:

[test loadValuesAsynchronouslyForKeys:@[@"playable",@"tracks"] completionHandler:^{
    // Now tracks is available
    NSLog(@" total tracks %@", test.tracks);
}];

Help!

Versions: RoboVM 2.3.9-SNAPSHOT

someguy233 avatar Feb 27 '20 06:02 someguy233

sadly apple doesn't expose @"playable",@"tracks" in way of global values (as it does for other keys) and API of AVAsset.loadValuesAsynchronouslyForKeys is build with sugared GlobalValueEnumeration. As there is no global values -- no global enum entry can be make for them. it might be done with workaround by changing type binding for this selector. Try snippet bellow (have not tested myself):

   public static void test() {
        AVAsset asset = new AVAsset();
        Workaround.fromAsset(asset).loadValuesAsynchronously(NSArray.fromStrings("playable", "tracks"), () -> {
            // done
        });
    }

    static class Workaround extends AVAsset {
        private Workaround(long handle) {
            super((Handle) null, handle);
        }

        static Workaround fromAsset(AVAsset asset) {
            return new Workaround(asset.getHandle());
        }

        @Method(selector = "loadValuesAsynchronouslyForKeys:completionHandler:")
        public native void loadValuesAsynchronously(NSArray<NSString> keys, @Block Runnable handler);
    }

dkimitsa avatar Feb 27 '20 09:02 dkimitsa

Thank you!... it does work.

imzahahs avatar Mar 05 '20 02:03 imzahahs