This repository has been archived by the owner on Sep 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add support for media files without video
- Loading branch information
Showing
3 changed files
with
110 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import AVKit | ||
import Foundation | ||
|
||
class TemporaryMediaFile { | ||
var url: URL? | ||
|
||
init(withData: Data) throws { | ||
let directory = FileManager.default.temporaryDirectory | ||
let fileName = "\(NSUUID().uuidString).mov" | ||
let url = directory.appendingPathComponent(fileName) | ||
do { | ||
try withData.write(to: url) | ||
self.url = url | ||
} catch { | ||
throw MarkersExtractorError.runtimeError("Error creating temporary file: \(error)") | ||
} | ||
} | ||
|
||
public var avAsset: AVAsset? { | ||
if let url = url { | ||
return AVAsset(url: url) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
public func deleteFile() { | ||
if let url = url { | ||
try? FileManager.default.removeItem(at: url) | ||
self.url = nil | ||
} | ||
} | ||
|
||
deinit { | ||
deleteFile() | ||
} | ||
} |