omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Casting NSArray from ObjCInstanceMethodProxy

    Pythonista
    msgproxy camera objc
    2
    5
    4767
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Trizard
      Trizard last edited by

      I'm new to Pythonista and the way objc_util interacts. Currently I trying to query the dual cameras on an IPhone 7 Plus.
      I'm using the new way to query cameras in OSX 10
      This is where I got stuck:

      from objc_util import *

      AVCaptureDeviceDiscoverySession = ObjCClass('AVCaptureDeviceDiscoverySession')

      session = AVCaptureDeviceDiscoverySession.discoverySessionWithDeviceTypes_mediaType_position_(['AVCaptureDeviceTypeBuiltInDuoCamera' , 'AVCaptureDeviceTypeBuiltInWideAngleCamera', 'AVCaptureDeviceTypeBuiltInTelephotoCamera'],ns('AVMediaTypeVideo'),ns('AVCaptureDevicePositionUnspecified'))

      How to implement the following line in Pythonista?

      NSArray<AVCaptureDevice *> *devices = session.devices;
      session.devices contains when I look at it on an iPhone 7 Plus (IOS 10.1beta):

      <objc_util.ObjCInstanceMethodProxy object at 0x10c1a7a20>
      How to cast from here to the NSArray AVCaptureDevice??
      .
      Many thanks for any hints!

      1 Reply Last reply Reply Quote 0
      • omz
        omz last edited by omz

        Call it like a function/method, i.e. session.devices() instead of session.devices.

        1 Reply Last reply Reply Quote 0
        • Trizard
          Trizard last edited by

          Thank you for the quick response. session.devices() returns empty even there should be a list of devices.
          Might be an issue how I call the new API.

          1 Reply Last reply Reply Quote 0
          • omz
            omz last edited by omz

            @Trizard Two things:

            1. The constant AVMediaTypeVideo actually has a value of 'vide' (you don't need to wrap this in an ns(...) call).

            2. AVCaptureDevicePosition is an enum (i.e. an integer), not a string, so you should just pass 0 for AVCaptureDevicePositionUnspecified.

            This seems to work (not tested on iPhone 7, but it does list both cameras on an iPad):

            from objc_util import *
            
            AVCaptureDeviceDiscoverySession = ObjCClass('AVCaptureDeviceDiscoverySession')
            
            types = ['AVCaptureDeviceTypeBuiltInDuoCamera' ,
                     'AVCaptureDeviceTypeBuiltInWideAngleCamera',
                     'AVCaptureDeviceTypeBuiltInTelephotoCamera']
            session = AVCaptureDeviceDiscoverySession.discoverySession(deviceTypes=types, mediaType='vide', position=0)
            
            devices = session.devices()
            print(devices)
            

            (I've prettified the syntax a little bit)

            1 Reply Last reply Reply Quote 0
            • Trizard
              Trizard last edited by

              Thank you! Yes it does work!
              On the 7 Plus I'm able to access all 4 cameras this way. This is what I get and it works perfect:

              (
              "<AVCaptureFigVideoDevice: 0x12db72c40 [Back Camera][com.apple.avfoundation.avcapturedevice.built-in_video:0]>",
              "<AVCaptureFigVideoDevice: 0x12dbeb240 [Front Camera][com.apple.avfoundation.avcapturedevice.built-in_video:1]>",
              "<AVCaptureFigVideoDevice: 0x12dbe1b20 [Back Telephoto Camera][com.apple.avfoundation.avcapturedevice.built-in_video:2]>",
              "<AVCaptureFigVideoDevice: 0x12dbe6bf0 [Back iSight Duo Camera][com.apple.avfoundation.avcapturedevice.built-in_video:3]>"
              )

              1 Reply Last reply Reply Quote 0
              • First post
                Last post
              Powered by NodeBB Forums | Contributors