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
-
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! -
Call it like a function/method, i.e.
session.devices()
instead ofsession.devices
. -
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. -
@Trizard Two things:
-
The constant
AVMediaTypeVideo
actually has a value of'vide'
(you don't need to wrap this in anns(...)
call). -
AVCaptureDevicePosition
is an enum (i.e. an integer), not a string, so you should just pass0
forAVCaptureDevicePositionUnspecified
.
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)
-
-
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]>"
)