Find out the type of media from URL in Swift

extension URL {
	var containsAudio: Bool {
		let uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension,
		                                                self.pathExtension as CFString,
		                                                nil)
		if UTTypeConformsTo((uti?.takeRetainedValue())!, kUTTypeAudio) {
			return true
		}
		return false
	}

	var containsVideo: Bool {
		let uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension,
		                                                self.pathExtension as CFString,
		                                                nil)
		if UTTypeConformsTo((uti?.takeRetainedValue())!, kUTTypeVideo) {
			return true
		}
		return false
	}

	var containsImage: Bool {
		let uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension,
		                                                self.pathExtension as CFString,
		                                                nil)
		if UTTypeConformsTo((uti?.takeRetainedValue())!, kUTTypeImage) {
			return true
		}
		return false
	}
}

In

,

Leave a Reply

Your email address will not be published. Required fields are marked *