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
04fa6ab0
Commit
04fa6ab0
authored
Dec 15, 2015
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated Presets enum for CaptureSession
parent
dc7dea2a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
12 deletions
+65
-12
Examples/Programmatic/CaptureView/CaptureView/ViewController.swift
+16
-3
Sources/CaptureSession.swift
+49
-9
No files found.
Examples/Programmatic/CaptureView/CaptureView/ViewController.swift
View file @
04fa6ab0
...
...
@@ -20,6 +20,11 @@ import UIKit
import
MaterialKit
import
AVFoundation
enum
CaptureMode
{
case
Photo
case
Video
}
class
ViewController
:
UIViewController
,
CapturePreviewViewDelegate
,
CaptureSessionDelegate
{
private
lazy
var
navigationBarView
:
NavigationBarView
=
NavigationBarView
()
private
lazy
var
captureView
:
CaptureView
=
CaptureView
()
...
...
@@ -30,6 +35,8 @@ class ViewController: UIViewController, CapturePreviewViewDelegate, CaptureSessi
private
lazy
var
flashButton
:
FlatButton
=
FlatButton
()
private
lazy
var
closeButton
:
FlatButton
=
FlatButton
()
private
lazy
var
captureMode
:
CaptureMode
=
.
Photo
override
func
viewDidLoad
()
{
super
.
viewDidLoad
()
prepareView
()
...
...
@@ -72,7 +79,7 @@ class ViewController: UIViewController, CapturePreviewViewDelegate, CaptureSessi
captureButton
.
pulseFill
=
true
captureButton
.
backgroundColor
=
MaterialColor
.
blue
.
darken1
.
colorWithAlphaComponent
(
0.3
)
captureButton
.
borderWidth
=
.
Border2
captureButton
.
borderColor
=
MaterialColor
.
grey
.
darken1
captureButton
.
borderColor
=
MaterialColor
.
white
captureButton
.
shadowDepth
=
.
None
captureButton
.
addTarget
(
self
,
action
:
"handleCaptureButton:"
,
forControlEvents
:
.
TouchUpInside
)
...
...
@@ -167,12 +174,16 @@ class ViewController: UIViewController, CapturePreviewViewDelegate, CaptureSessi
:name: handleCaptureButton
*/
internal
func
handleCaptureButton
(
button
:
UIButton
)
{
if
.
Photo
==
captureMode
{
captureView
.
captureSession
.
captureStillImage
()
}
else
if
.
Video
==
captureMode
{
if
captureView
.
captureSession
.
isRecording
{
captureView
.
captureSession
.
stopRecording
()
}
else
{
captureView
.
captureSession
.
startRecording
()
}
}
}
/**
:name: handleSwitchCameraButton
...
...
@@ -219,6 +230,7 @@ class ViewController: UIViewController, CapturePreviewViewDelegate, CaptureSessi
*/
func
handleCameraButton
(
button
:
UIButton
)
{
captureButton
.
backgroundColor
=
MaterialColor
.
blue
.
darken1
.
colorWithAlphaComponent
(
0.3
)
captureMode
=
.
Photo
}
/**
...
...
@@ -226,6 +238,7 @@ class ViewController: UIViewController, CapturePreviewViewDelegate, CaptureSessi
*/
func
handleVideoButton
(
button
:
UIButton
)
{
captureButton
.
backgroundColor
=
MaterialColor
.
red
.
darken1
.
colorWithAlphaComponent
(
0.3
)
captureMode
=
.
Video
}
/**
...
...
@@ -253,14 +266,14 @@ class ViewController: UIViewController, CapturePreviewViewDelegate, CaptureSessi
:name: captureDidStartRecordingToOutputFileAtURL
*/
func
captureDidStartRecordingToOutputFileAtURL
(
capture
:
CaptureSession
,
captureOutput
:
AVCaptureFileOutput
,
fileURL
:
NSURL
,
fromConnections
connections
:
[
AnyObject
])
{
print
(
"Capture Started Recording"
)
print
(
"Capture Started Recording
\(
fileURL
)
"
)
}
/**
:name: captureDidFinishRecordingToOutputFileAtURL
*/
func
captureDidFinishRecordingToOutputFileAtURL
(
capture
:
CaptureSession
,
captureOutput
:
AVCaptureFileOutput
,
outputFileURL
:
NSURL
,
fromConnections
connections
:
[
AnyObject
],
error
:
NSError
!
)
{
print
(
"Capture Stopped Recording"
)
print
(
"Capture Stopped Recording
\(
outputFileURL
)
"
)
}
}
Sources/CaptureSession.swift
View file @
04fa6ab0
...
...
@@ -22,7 +22,18 @@ import AVFoundation
private
var
CaptureSessionAdjustingExposureContext
:
UInt8
=
1
public
enum
CaptureSessionPreset
{
case
High
case
PresetPhoto
case
PresetHigh
case
PresetMedium
case
PresetLow
case
Preset352x288
case
Preset640x480
case
Preset1280x720
case
Preset1920x1080
case
Preset3840x2160
case
PresetiFrame960x540
case
PresetiFrame1280x720
case
PresetInputPriority
}
/**
...
...
@@ -30,8 +41,34 @@ public enum CaptureSessionPreset {
*/
public
func
CaptureSessionPresetToString
(
preset
:
CaptureSessionPreset
)
->
String
{
switch
preset
{
case
.
High
:
case
.
PresetPhoto
:
return
AVCaptureSessionPresetPhoto
case
.
PresetHigh
:
return
AVCaptureSessionPresetHigh
case
.
PresetMedium
:
return
AVCaptureSessionPresetMedium
case
.
PresetLow
:
return
AVCaptureSessionPresetLow
case
.
Preset352x288
:
return
AVCaptureSessionPreset352x288
case
.
Preset640x480
:
return
AVCaptureSessionPreset640x480
case
.
Preset1280x720
:
return
AVCaptureSessionPreset1280x720
case
.
Preset1920x1080
:
return
AVCaptureSessionPreset1920x1080
case
.
Preset3840x2160
:
if
#available(iOS 9.0, *)
{
return
AVCaptureSessionPreset3840x2160
}
else
{
return
AVCaptureSessionPresetHigh
}
case
.
PresetiFrame960x540
:
return
AVCaptureSessionPresetiFrame960x540
case
.
PresetiFrame1280x720
:
return
AVCaptureSessionPresetiFrame1280x720
case
.
PresetInputPriority
:
return
AVCaptureSessionPresetInputPriority
}
}
...
...
@@ -101,6 +138,11 @@ public class CaptureSession : NSObject, AVCaptureFileOutputRecordingDelegate {
private
lazy
var
movieOutput
:
AVCaptureMovieFileOutput
=
AVCaptureMovieFileOutput
()
/**
:name: movieOutputURL
*/
private
var
movieOutputURL
:
NSURL
?
/**
:name: session
*/
internal
lazy
var
session
:
AVCaptureSession
=
AVCaptureSession
()
...
...
@@ -116,11 +158,6 @@ public class CaptureSession : NSObject, AVCaptureFileOutputRecordingDelegate {
public
private(set)
lazy
var
isRecording
:
Bool
=
false
/**
:name: movieOutputURL
*/
public
private(set)
var
movieOutputURL
:
NSURL
?
/**
:name: activeCamera
*/
public
var
activeCamera
:
AVCaptureDevice
?
{
...
...
@@ -131,7 +168,7 @@ public class CaptureSession : NSObject, AVCaptureFileOutputRecordingDelegate {
:name: init
*/
public
override
init
()
{
sessionPreset
=
.
High
sessionPreset
=
.
Preset
High
super
.
init
()
prepareSession
()
}
...
...
@@ -630,7 +667,10 @@ public class CaptureSession : NSObject, AVCaptureFileOutputRecordingDelegate {
private
func
uniqueURL
()
->
NSURL
?
{
do
{
let
directory
:
NSURL
=
try
NSFileManager
.
defaultManager
()
.
URLForDirectory
(
.
DocumentDirectory
,
inDomain
:
.
UserDomainMask
,
appropriateForURL
:
nil
,
create
:
true
)
return
directory
.
URLByAppendingPathComponent
(
"temp_movie.mov"
)
let
dateFormatter
=
NSDateFormatter
()
dateFormatter
.
dateStyle
=
.
FullStyle
dateFormatter
.
timeStyle
=
.
FullStyle
return
directory
.
URLByAppendingPathComponent
(
dateFormatter
.
stringFromDate
(
NSDate
())
+
".mov"
)
}
catch
let
e
as
NSError
{
delegate
?
.
captureCreateMovieFileFailedWithError
?(
self
,
error
:
e
)
}
...
...
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