10. Media
ARGear provides photo capture and video recording features through ARGMedia in ratios of 16:9, 4:3, 1:1.
Before using camera functions, video device information must be provided to ARGMedia Class.
Sample code below shows how to set relevant information.
Objective-C
Swift
1
// Sample Code. Setting Video Device Information in ARGMedia Class
2
3
// videoDevice: AVCaptureDevice
4
// videoDeviceOrientation: AVCaptureVideoOrientation
5
// videoConnection: AVCaptureConnection
6
// mediaRatio: ARGMediaRatio
7
// videoBitrate: ARGMediaVideoBitrate
8
9
ARGMedia *argMedia = [[ARGMedia alloc] init];
10
11
[argMedia setVideoDevice:device];
12
[argMedia setVideoDeviceOrientation:videoDeviceOrientation];
13
[argMedia setVideoConnection:videoConnection];
14
[argMedia setMediaRatio:ARGMediaRatio_4x3];
15
[argMedia setVideoBitrate:ARGMediaVideoBitrate_2M];
Copied!
1
// Sample Code. Setting Video Device Information in ARGMedia Class
2
3
// videoDevice: AVCaptureDevice
4
// videoDeviceOrientation: AVCaptureVideoOrientation
5
// videoConnection: AVCaptureConnection
6
// mediaRatio: ARGMediaRatio
7
// videoBitrate: ARGMediaVideoBitrate
8
9
var arMedia = ARGMedia()
10
11
arMedia.setVideoDevice(arCamera.cameraDevice)
12
arMedia.setVideoDeviceOrientation(arCamera.cameraConnection.videoOrientation)
13
arMedia.setVideoConnection(arCamera.cameraConnection)
14
arMedia.setMediaRatio(._4x3)
15
arMedia.setVideoBitrate(._2M)
Copied!

10.1 Take a Photo

Using the takePicture function in ARGMedia, users can take a photo of the current rendered ARGFrame. After a photo is captured, the photo is converted into a UIImage and is accessible in the closure interface.
Sample code below shows how to get the captured photo.
Objective-C
Swift
1
// Sample Code. Getting a Captured Image
2
3
UIImageView *imageView = [[UIImageView alloc] init];
4
[_argMedia takePic:^(UIImage * _Nonnull image) {
5
[imageView setImage:image];
6
}];
Copied!
1
// Sample Code. Getting a Captured Image
2
3
let imageView = UIImageView(frame: frame)
4
arMedia.takePic { image in
5
imageView.image = image
6
}
Copied!

10.2 Record a Video

By calling recordVideoStart and recordVideoStop method in ARGMedia class, you can start or stop video recording. Recorded video must be converted into a NSDictionary.
Sample code below shows how to obtain a recorded video.
Objective-C
Swift
1
// Sample Code. Start and Stop Video Recording
2
3
ARGMedia *argMedia = [[ARGMedia alloc] init];
4
5
6
// Start Video Recording
7
[argMedia recordVideoStart:^(CGFloat recTime) {
8
dispatch_async(dispatch_get_main_queue(), ^{
9
// recTime represents recorded time
10
});
11
}];
12
13
// Stop Video Recording
14
[argMedia recordVideoStop:^(NSDictionary * _Nonnull videoInfo) {
15
} save:^(NSDictionary * _Nonnull videoInfo) {
16
// converting video data into NSDictionary form
17
}];
Copied!
1
// Sample Code. Start and Stop Video Recording
2
3
// Start Video Recording
4
arMedia.recordVideoStart { (sec) in
5
// recTime represents recorded time
6
}
7
8
// Stop Video Recording
9
arMedia.recordVideoStop({ (videoInfo) in
10
}) { (resultVideoInfo) in
11
// convert video data into NSDictionary form
12
}
Copied!
Last modified 1yr ago