loop-play video in iMessage

Hi,

An mp4 video created in an iMessage Extention App doesn't autoplay in iMessage - requires tap on it to play.
How to format video file so it will start loop-play in iMessage?

Thanks!

You need to set the appropriate metadata tag in the mp4 video. See the "LOOP" user data atom in https://developer.apple.com/library/content/documentation/QuickTime/QTFF/QTFFChap2/qtff2.html.

Is there a way to hide play button from this looped video?

How does one actually set the user data LOOP atom in a AVMutableMetadataItem? There seems to be no type for it defined, such as there is for quickTimeUserDataKeyAuthor


Thinking something like this?

        let metadata = AVMutableMetadataItem()
        metadata.keySpace = AVMetadataKeySpace.quickTimeUserData
        metadata.key = "LOOP" as NSCopying & NSObjectProtocol
        metadata.value = UInt32(0) as NSCopying & NSObjectProtocol
        
        let exporter = AVAssetExportSession(asset: asset, presetName: AVAssetExportPresetHighestQuality)
        exporter.metadata = [metadata]


But doesn't have any effect on the video...

I have tried this:

let loopStyleItem = AVMutableMetadataItem()
loopStyleItem.identifier = AVMutableMetadataItem.identifier(forKey: "LOOP", keySpace: .quickTimeUserData)
loopStyleItem.value = NSNumber(value: UInt32(0))

But it seems this value is being stripped out upon export. I can write custom values to quickTimeMetadata, but custom values in quickTimeUserData are removed. Has anyone figured this out?

loop-play video in iMessage
 
 
Q