问题描述:

My understanding currently is that:

CameraUI

  1. I can use the CameraUI to access the built in camera for MediaType.VIDEO and that delegates to the built-in video camera app and lets me record a video. My app does that now.

  2. When I stop recording and click the "Use" button, I am returned to my app and theoretically I have a valid MediaPromise.

  3. iOS does -not- provide a valid/usable url/filename to the recorded video (or to photos) and so I would have to use a Loader to bring-in/use/access the 'recorded' video... AND... iOS does not actually create a file anywhere on the device, most importantly, in the Camera Roll where one would expect by the normal behavior when uses the system native camera/video app.

  4. The documentation says that the Loader can load various image types and SWFs but nothing about video data, so I conclude from that that I cannot actually use the CameraUI to generate a valid MediaPromise that I can then pass to a Loader class or similar to read in the information created by the system camera and then manipulate (upload, save to applicationStorageDirectory, and/or display in one of the two video player components available in the API).

CameraRoll

  1. I can have video entities in the iOS Camera Roll but the AS3/Air3.5 CameraRoll class won't let me view/access/reference them in any way.

Normal File I/O

  1. All my attempts to use the Air3.5 File classes to browse to the storage location of the iOS Camera Roll have been rebuffed.

------- Questions -------

  1. Am I correct in believing that there is a way to take video but no way to use the video that's been captured. (No way to use the resulting MediaPromise successfully).

  2. I believe you can take video and access it using Android, but there's nothing in the documentation that says that you cannot using iOS.

  3. Am I correct in believing that iOS sandboxes apps so that they cannot browse to video/photo storage using standard File I/O, but only through the apparently non-workable means I've tried (CameraUI & CameraRoll)

  4. Am I wrong to think that these should be rather obvious NEEDS that one can achieve using the XCode Objective C++ etc route but the AIR Mobile Framework does not allow either because of Apple blocking functionality or because Adobe has failed to meet reasonable expectations?

One item of ironic note to convey. If I use the iOS system camera app to record a video, a thumnail of that video then appears in the Gallery/Camera Roll, and of course, I can share it or view it, or whatever... If I use AIR's CameraRoll.browseForImage(), provided I haven't used the camera to take another image, when it shows me the folder where the pictures are stored, the folder icon uses the thumbnail of the last object added... in this case, the video I took, but if I then enter the folder, the video cannot be found. It's teasing us. It knows it's there, but it is apparently forbidden fruit.

网友答案:

I can't answer all your questions, so this entry may not be acceptable, but I found this page while searching a solution for some the problems you described and thought that someone else may find this answer (partially) useful.

To save the movie you just took you need to open and read the data from the promise.
The iOS won't save the file anywere, so the MediaPromise.file is always null.

This is my solution to the problem:

private var camera:CameraUI;
private var dataInput:IDataInput;

public function recordVideo():void
{
    // Start the camera and ask for a video
    camera = new CameraUI();
    camera.addEventListener(MediaEvent.COMPLETE, onCameraComplete);
    camera.launch(MediaType.VIDEO);
}

private function onCameraComplete(event:MediaEvent):void
{   
    // event.data is a MediaPromise and MediaPromise.open() returns a IDataInput
    // Let's cast it to a dispatcher and check when it's complete
    dataInput = event.data.open();
    var dispatcher:IEventDispatcher = IEventDispatcher(dataInput);
    dispatcher.addEventListener(Event.COMPLETE, onDataInputComplete);
}

private function onDataInputComplete(event:Event):void 
{
    // We can do whatever we want with the data, so we'll store it in a File
    var file:File = new File();
    var bytes:ByteArray = new ByteArray();
    var stream:FileStream = new FileStream();

    // Reading the data from the opened MediaPromise
    dataInput.readBytes(bytes);

    stream.open(file, FileMode.WRITE);
    stream.writeBytes(bytes, 0, bytes.bytesAvailable);
    stream.close();
}

Also, I'm still looking for a way to put the movie in the CameraRoll

相关阅读:
Top