Created
November 6, 2013 01:36
-
-
Save jcutrell/7329489 to your computer and use it in GitHub Desktop.
ALAsset reading data for upload
This file contains hidden or 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
def assets_library | |
@_assets_library ||= ALAssetsLibrary.alloc.init | |
end | |
@foo.clips.each_with_index do |clip,i| | |
# clip[1][:reference_url] refers to a video file chosen via BW::Device.camera.any.picture(media_types: [:movie]) do |result| | |
asset_url = clip[1][:reference_url] | |
assets_library.assetForURL(asset_url, resultBlock: lambda { |asset| | |
selectedAsset = asset | |
byteArraySize = selectedAsset.defaultRepresentation.size | |
rawData = NSMutableData.alloc.initWithCapacity(byteArraySize) | |
bufferPointer = rawData.mutableBytes | |
error = Pointer.new(:object) | |
selectedAsset.defaultRepresentation.getBytes(bufferPointer, fromOffset:0, length:byteArraySize, error:error) | |
rawData = NSMutableData.dataWithBytes(bufferPointer, length:byteArraySize) | |
clip[2] = rawData | |
if ([email protected] and [email protected]_started) | |
run_request | |
end | |
completion_block.call(nil) if block_given? | |
}, failureBlock: lambda {|error| | |
puts error | |
}) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment