1
Fork 0
This repository has been archived on 2025-04-12. You can view files and clone it, but cannot push or open issues or pull requests.
silica-viewer/ProcreateViewer/TimelapseViewController.swift

37 lines
1.1 KiB
Swift

import Foundation
import Cocoa
import AVKit
import AVFoundation
import ZIPFoundation
class TimelapseViewController: NSViewController {
var document: Document?
@IBOutlet weak var playerView: AVPlayerView!
override func viewWillAppear() {
super.viewDidAppear()
guard let archive = Archive(data: (document?.data)!, accessMode: Archive.AccessMode.read) else {
return
}
let directory = NSTemporaryDirectory()
var entries: [AVPlayerItem] = []
for entry in archive.makeIterator() {
if entry.path.contains(VideoPath) {
let fileName = NSUUID().uuidString + ".mp4"
// This returns a URL? even though it is an NSURL class method
let fullURL = NSURL.fileURL(withPathComponents: [directory, fileName])!
try? archive.extract(entry, to: fullURL)
entries.append(AVPlayerItem(url: fullURL))
}
}
playerView?.player = AVQueuePlayer(items: entries)
}
}