Forum Archive

Casting NSArray from ObjCInstanceMethodProxy

Trizard

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 *devices = session.devices;
session.devices contains when I look at it on an iPhone 7 Plus (IOS 10.1beta):


How to cast from here to the NSArray AVCaptureDevice??
.
Many thanks for any hints!

omz

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

Trizard

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.

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)

Trizard

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:

(
"",
"",
"",
""
)