Created
August 6, 2017 16:25
-
-
Save sparrow/ffcf5f782751e94682512a873a5d72f9 to your computer and use it in GitHub Desktop.
This is a Swift code snippet that we used for our blog post at RubyGarage https://rubygarage.org/. To add an image and text over a video.
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
if let item = MediaItem(url: url) { | |
let logoImage = UIImage(named: "logo") | |
let firstElement = MediaElement(image: logoImage!) | |
firstElement.frame = CGRect(x: 0, y: 0, width: logoImage!.size.width, height: logoImage!.size.height) | |
let testStr = "Attributed Text" | |
let attributes = [ NSForegroundColorAttributeName: UIColor.white, NSFontAttributeName: UIFont.systemFont(ofSize: 35) ] | |
let attrStr = NSAttributedString(string: testStr, attributes: attributes) | |
let secondElement = MediaElement(text: attrStr) | |
secondElement.frame = CGRect(x: 300, y: 300, width: logoImage!.size.width, height: logoImage!.size.height) | |
item.add(elements: [firstElement, secondElement]) | |
let mediaProcessor = MediaProcessor() | |
mediaProcessor.processElements(item: item) { [weak self] (result, error) in | |
self?.videoPlayer.url = result.processedUrl | |
self?.videoPlayer.playFromBeginning() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment