Name: RxMediaPicker
Owner: RxSwift Community
Description: A reactive wrapper built around UIImagePickerController.
Created: 2016-02-06 00:54:43.0
Updated: 2018-01-06 21:05:48.0
Pushed: 2017-10-21 09:22:21.0
Size: 52
Language: Swift
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
RxMediaPicker is a RxSwift wrapper built around UIImagePickerController consisting in a simple interface for common actions like picking photos or videos stored on the device, recording a video or taking a photo.
If you ever used UIImagePickerController you know how it can become quite verbose and introduce some unnecessary complexity, as you use the same class to do everything, from picking photos or videos from the library, recording videos, etc. At the same time, you have all these different properties and methods which can be used when you are dealing with photos, others for when you're dealing with videos, and others in all cases.
If you're interested, check the resulting article RxMediaPicker???picking photos and videos the cool kids? way!
Note: As RxMediaPicker is still in its early days, the interface may change in future versions.
For a more complete example please check the demo app included (ideally run it on a device). This is how you would record a video using the camera:
rt RxMediaPicker
rt RxSwift
picker: RxMediaPicker!
disposeBag = DisposeBag()
ride func viewDidLoad() {
super.viewDidLoad()
picker = RxMediaPicker(delegate: self)
recordVideo() {
picker.recordVideo(maximumDuration: 10, editable: true)
.observeOn(MainScheduler.instance)
.subscribe(onNext: { url in
// Do something with the video url obtained!
}, onError: { error in
print("Error occurred!")
}, onCompleted: {
print("Completed")
}, onDisposed: {
print("Disposed")
})
.addDisposableTo(disposeBag)
Based on their names, the operations available on RxMediaPicker should be self-explanatory. You can record a video, or pick an existing one stored on the device, and the same thing happens for photos. The only thing to note here is that picking a video will get you the video url, and picking a photo will get you a tuple consisting in the original image and an optional edited image (if any edits were made).
recordVideo(device device: UIImagePickerControllerCameraDevice = .Rear,
quality: UIImagePickerControllerQualityType = .TypeMedium,
maximumDuration: NSTimeInterval = 600, editable: Bool = false) -> Observable<NSURL>
wift
selectVideo(source: UIImagePickerControllerSourceType = .PhotoLibrary,
maximumDuration: NSTimeInterval = 600, editable: Bool = false) -> Observable<NSURL>
wift
takePhoto(device device: UIImagePickerControllerCameraDevice = .Rear,
flashMode: UIImagePickerControllerCameraFlashMode = .Auto,
editable: Bool = false) -> Observable<(UIImage, UIImage?)>
wift
selectImage(source: UIImagePickerControllerSourceType = .PhotoLibrary,
editable: Bool = false) -> Observable<(UIImage, UIImage?)>
presentPicker(picker: UIImagePickerController)
dismissPicker(picker: UIImagePickerController)
To be able to use RxMediaPicker you will need to adopt the protocol RxMediaPickerDelegate. This is required to indicate RxMediaPicker how the camera/photos picker should be presented. For example, you may want to present the photos library picker in a popover on the iPad, and use the entire screen on the iPhone.
CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:
m install cocoapods
To integrate RxMediaPicker into your Xcode project using CocoaPods, include this in your Podfile:
form :ios, '8.0'
frameworks!
'RxMediaPicker'
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.
You can install Carthage with Homebrew using the following command:
ew update
ew install carthage
To integrate RxMediaPicker into your Xcode project using Carthage, specify it in your Cartfile
:
ub "RxSwiftCommunity/RxMediaPicker" "master"
Run carthage
to build the framework and drag the built RxMediaPicker.framework
into your Xcode project.
Owned and maintained by Rui Costa (@ruipfcosta).
Bug reports and pull requests are welcome.
RxMediaPicker is released under the MIT license. See LICENSE for details.