Converting an attachment into video on iOS (swift)

Hello

I have a CBL document (synced via SyncGateway) with several attachments. I can easily convert images in UI-Images in Swift, but how can I convert a video from an attachment into a valid video file for iOS (mp4) (with AVFoundation)?

Is there a possibility to access the video directly on the devices file system via URL?

Thank you very much in advance.

Regards

Sascha

Hello,

I have never tried this myself, but I guessed you could use CBLAttachment.contentURL property to play the movie with AVPlayer.

hi @pasin, it says in CBLAttachment.h that contentURL is somewhat deprecated:

/** The (file:) URL of the file containing the contents.
    This property is somewhat deprecated and is made available only for use with platform APIs that
    require file paths/URLs, e.g. some media playback APIs. Whenever possible, use the `content`
    property or the `openContentStream` method instead.
    The file must be treated as read-only! DO NOT MODIFY OR DELETE IT.
    If the database is encrypted, attachment files are also encrypted and not directly readable,
    so this property will return nil. */
@property (readonly, nullable) NSURL* contentURL;

Since attachment needs Data, what I attached is converted video into Data. The attachment looks like this:

"_attachments": {
    "VIDEOA2A2FBB0-0898-4A84-9938-D499852E6A1B": {
      "content_type": "video/quicktime",
      "digest": "sha1-0Yh2FtfBpOaAEMcln9Bhnndksdg=",
      "length": 443140,
      "revpos": 1,
      "stub": true
    }
  }

But I’m having trouble getting the video URL so that I can display/play the video. I also tried contentURL but i’m getting null.

I’m about to try openContentStream though =D

Thanks.

contentURL will be nil if the database is encrypted, since in that case the attachment file is encrypted on disk so it would be unreadable to you.

If you can play the video without requiring a file URL, using a stream instead, that would be optimal.