Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
Material
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitriy Stepanets
Material
Commits
61a63660
Commit
61a63660
authored
Dec 15, 2015
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated CaptureView example to display video recording duration
parent
04fa6ab0
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
109 additions
and
6 deletions
+109
-6
Examples/Programmatic/CaptureView/CaptureView/ViewController.swift
+90
-2
Sources/CaptureSession.swift
+19
-4
No files found.
Examples/Programmatic/CaptureView/CaptureView/ViewController.swift
View file @
61a63660
...
...
@@ -35,7 +35,9 @@ class ViewController: UIViewController, CapturePreviewViewDelegate, CaptureSessi
private
lazy
var
flashButton
:
FlatButton
=
FlatButton
()
private
lazy
var
closeButton
:
FlatButton
=
FlatButton
()
private
lazy
var
captureMode
:
CaptureMode
=
.
Photo
private
lazy
var
captureMode
:
CaptureMode
=
.
Video
private
var
timer
:
NSTimer
?
override
func
viewDidLoad
()
{
super
.
viewDidLoad
()
...
...
@@ -66,6 +68,24 @@ class ViewController: UIViewController, CapturePreviewViewDelegate, CaptureSessi
navigationBarView
.
shadowDepth
=
.
None
navigationBarView
.
statusBarStyle
=
.
LightContent
// Title label.
let
titleLabel
:
UILabel
=
UILabel
()
titleLabel
.
text
=
"00:00:00"
titleLabel
.
textAlignment
=
.
Left
titleLabel
.
textColor
=
MaterialColor
.
white
titleLabel
.
font
=
RobotoFont
.
regularWithSize
(
20
)
navigationBarView
.
titleLabel
=
titleLabel
navigationBarView
.
titleLabelInsetsRef
.
left
=
64
// Detail label
let
detailLabel
:
UILabel
=
UILabel
()
detailLabel
.
text
=
"Stopped"
detailLabel
.
textAlignment
=
.
Left
detailLabel
.
textColor
=
MaterialColor
.
white
detailLabel
.
font
=
RobotoFont
.
regularWithSize
(
12
)
navigationBarView
.
detailLabel
=
detailLabel
navigationBarView
.
detailLabelInsetsRef
.
left
=
64
view
.
addSubview
(
navigationBarView
)
navigationBarView
.
leftButtons
=
[
closeButton
]
navigationBarView
.
rightButtons
=
[
switchCameraButton
,
flashButton
]
...
...
@@ -77,7 +97,7 @@ class ViewController: UIViewController, CapturePreviewViewDelegate, CaptureSessi
private
func
prepareCaptureButton
()
{
captureButton
.
pulseColor
=
MaterialColor
.
white
captureButton
.
pulseFill
=
true
captureButton
.
backgroundColor
=
MaterialColor
.
blue
.
darken1
.
colorWithAlphaComponent
(
0.3
)
captureButton
.
backgroundColor
=
MaterialColor
.
red
.
darken1
.
colorWithAlphaComponent
(
0.3
)
captureButton
.
borderWidth
=
.
Border2
captureButton
.
borderColor
=
MaterialColor
.
white
captureButton
.
shadowDepth
=
.
None
...
...
@@ -179,8 +199,10 @@ class ViewController: UIViewController, CapturePreviewViewDelegate, CaptureSessi
}
else
if
.
Video
==
captureMode
{
if
captureView
.
captureSession
.
isRecording
{
captureView
.
captureSession
.
stopRecording
()
stopTimer
()
}
else
{
captureView
.
captureSession
.
startRecording
()
startTimer
()
}
}
}
...
...
@@ -207,6 +229,7 @@ class ViewController: UIViewController, CapturePreviewViewDelegate, CaptureSessi
:name: handleFlashButton
*/
internal
func
handleFlashButton
(
button
:
UIButton
)
{
if
.
Back
==
captureView
.
captureSession
.
cameraPosition
{
var
img
:
UIImage
?
switch
captureView
.
captureSession
.
flashMode
{
...
...
@@ -224,6 +247,7 @@ class ViewController: UIViewController, CapturePreviewViewDelegate, CaptureSessi
flashButton
.
setImage
(
img
,
forState
:
.
Normal
)
flashButton
.
setImage
(
img
,
forState
:
.
Highlighted
)
}
}
/**
:name: handleCameraButton
...
...
@@ -231,6 +255,8 @@ class ViewController: UIViewController, CapturePreviewViewDelegate, CaptureSessi
func
handleCameraButton
(
button
:
UIButton
)
{
captureButton
.
backgroundColor
=
MaterialColor
.
blue
.
darken1
.
colorWithAlphaComponent
(
0.3
)
captureMode
=
.
Photo
navigationBarView
.
titleLabel
!.
text
=
""
navigationBarView
.
detailLabel
!.
text
=
""
}
/**
...
...
@@ -239,6 +265,8 @@ class ViewController: UIViewController, CapturePreviewViewDelegate, CaptureSessi
func
handleVideoButton
(
button
:
UIButton
)
{
captureButton
.
backgroundColor
=
MaterialColor
.
red
.
darken1
.
colorWithAlphaComponent
(
0.3
)
captureMode
=
.
Video
navigationBarView
.
titleLabel
!.
text
=
"00:00:00"
navigationBarView
.
detailLabel
!.
text
=
"Stopped"
}
/**
...
...
@@ -249,6 +277,30 @@ class ViewController: UIViewController, CapturePreviewViewDelegate, CaptureSessi
}
/**
:name: captureSessionWillSwitchCameras
*/
func
captureSessionWillSwitchCameras
(
capture
:
CaptureSession
,
position
:
AVCaptureDevicePosition
)
{
if
.
Back
==
position
{
let
img
:
UIImage
?
=
UIImage
(
named
:
"ic_flash_off_white"
)
captureView
.
captureSession
.
flashMode
=
.
Off
flashButton
.
setImage
(
img
,
forState
:
.
Normal
)
flashButton
.
setImage
(
img
,
forState
:
.
Highlighted
)
}
}
/**
:name: captureSessionDidSwitchCameras
*/
func
captureSessionDidSwitchCameras
(
capture
:
CaptureSession
,
position
:
AVCaptureDevicePosition
)
{
if
.
Back
==
position
{
let
img
:
UIImage
?
=
UIImage
(
named
:
"ic_flash_auto_white"
)
captureView
.
captureSession
.
flashMode
=
.
Auto
flashButton
.
setImage
(
img
,
forState
:
.
Normal
)
flashButton
.
setImage
(
img
,
forState
:
.
Highlighted
)
}
}
/**
:name: captureStillImageAsynchronously
*/
func
captureStillImageAsynchronously
(
capture
:
CaptureSession
,
image
:
UIImage
)
{
...
...
@@ -275,5 +327,41 @@ class ViewController: UIViewController, CapturePreviewViewDelegate, CaptureSessi
func
captureDidFinishRecordingToOutputFileAtURL
(
capture
:
CaptureSession
,
captureOutput
:
AVCaptureFileOutput
,
outputFileURL
:
NSURL
,
fromConnections
connections
:
[
AnyObject
],
error
:
NSError
!
)
{
print
(
"Capture Stopped Recording
\(
outputFileURL
)
"
)
}
/**
:name: startTimer
*/
func
startTimer
()
{
timer
?
.
invalidate
()
timer
=
NSTimer
(
timeInterval
:
0.5
,
target
:
self
,
selector
:
"updateTimer"
,
userInfo
:
nil
,
repeats
:
true
)
NSRunLoop
.
mainRunLoop
()
.
addTimer
(
timer
!
,
forMode
:
NSRunLoopCommonModes
)
navigationBarView
.
detailLabel
!.
textColor
=
MaterialColor
.
red
.
accent1
captureButton
.
backgroundColor
=
MaterialColor
.
red
.
darken4
.
colorWithAlphaComponent
(
0.3
)
}
/**
:name: updateTimer
*/
func
updateTimer
()
{
let
duration
:
CMTime
=
captureView
.
captureSession
.
recordedDuration
let
time
:
Double
=
CMTimeGetSeconds
(
duration
)
let
hours
:
Int
=
Int
(
time
/
3600
)
let
minutes
:
Int
=
Int
((
time
/
60
)
%
60
)
let
seconds
:
Int
=
Int
(
time
%
60
)
navigationBarView
.
titleLabel
!.
text
=
String
(
format
:
"%02i:%02i:%02i"
,
arguments
:
[
hours
,
minutes
,
seconds
])
navigationBarView
.
detailLabel
!.
text
=
"Recording"
}
/**
:name: stopTimer
*/
func
stopTimer
()
{
timer
?
.
invalidate
()
timer
=
nil
navigationBarView
.
titleLabel
!.
text
=
"00:00:00"
navigationBarView
.
detailLabel
!.
text
=
"Stopped"
navigationBarView
.
detailLabel
!.
textColor
=
MaterialColor
.
white
captureButton
.
backgroundColor
=
MaterialColor
.
red
.
darken1
.
colorWithAlphaComponent
(
0.3
)
}
}
Sources/CaptureSession.swift
View file @
61a63660
...
...
@@ -80,6 +80,16 @@ public protocol CaptureSessionDelegate {
optional
func
captureSessionFailedWithError
(
capture
:
CaptureSession
,
error
:
NSError
)
/**
:name: captureSessionDidSwitchCameras
*/
optional
func
captureSessionDidSwitchCameras
(
capture
:
CaptureSession
,
position
:
AVCaptureDevicePosition
)
/**
:name: captureSessionWillSwitchCameras
*/
optional
func
captureSessionWillSwitchCameras
(
capture
:
CaptureSession
,
position
:
AVCaptureDevicePosition
)
/**
:name: captureStillImageAsynchronously
*/
optional
func
captureStillImageAsynchronously
(
capture
:
CaptureSession
,
image
:
UIImage
)
...
...
@@ -158,6 +168,13 @@ public class CaptureSession : NSObject, AVCaptureFileOutputRecordingDelegate {
public
private(set)
lazy
var
isRecording
:
Bool
=
false
/**
:name: recordedDuration
*/
public
var
recordedDuration
:
CMTime
{
return
movieOutput
.
recordedDuration
}
/**
:name: activeCamera
*/
public
var
activeCamera
:
AVCaptureDevice
?
{
...
...
@@ -377,8 +394,8 @@ public class CaptureSession : NSObject, AVCaptureFileOutputRecordingDelegate {
*/
public
func
switchCameras
()
{
if
canSwitchCameras
{
dispatch_async
(
videoQueue
)
{
do
{
self
.
delegate
?
.
captureSessionWillSwitchCameras
?(
self
,
position
:
self
.
cameraPosition
)
let
videoInput
:
AVCaptureDeviceInput
?
=
try
AVCaptureDeviceInput
(
device
:
self
.
inactiveCamera
!
)
self
.
session
.
beginConfiguration
()
self
.
session
.
removeInput
(
self
.
activeVideoInput
)
...
...
@@ -390,12 +407,12 @@ public class CaptureSession : NSObject, AVCaptureFileOutputRecordingDelegate {
self
.
session
.
addInput
(
self
.
activeVideoInput
)
}
self
.
session
.
commitConfiguration
()
self
.
delegate
?
.
captureSessionDidSwitchCameras
?(
self
,
position
:
self
.
cameraPosition
)
}
catch
let
e
as
NSError
{
self
.
delegate
?
.
captureSessionFailedWithError
?(
self
,
error
:
e
)
}
}
}
}
/**
:name: isFocusModeSupported
...
...
@@ -541,7 +558,6 @@ public class CaptureSession : NSObject, AVCaptureFileOutputRecordingDelegate {
:name: startRecording
*/
public
func
startRecording
()
{
dispatch_async
(
videoQueue
)
{
if
!
self
.
isRecording
{
let
connection
:
AVCaptureConnection
=
self
.
movieOutput
.
connectionWithMediaType
(
AVMediaTypeVideo
)
connection
.
videoOrientation
=
self
.
currentVideoOrientation
...
...
@@ -564,7 +580,6 @@ public class CaptureSession : NSObject, AVCaptureFileOutputRecordingDelegate {
}
}
}
}
/**
:name: captureOutput
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment