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
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
16 deletions
+69
-16
Examples/Programmatic/CaptureView/CaptureView/ViewController.swift
+20
-7
Sources/CaptureSession.swift
+49
-9
No files found.
Examples/Programmatic/CaptureView/CaptureView/ViewController.swift
View file @
04fa6ab0
...
@@ -20,6 +20,11 @@ import UIKit
...
@@ -20,6 +20,11 @@ import UIKit
import
MaterialKit
import
MaterialKit
import
AVFoundation
import
AVFoundation
enum
CaptureMode
{
case
Photo
case
Video
}
class
ViewController
:
UIViewController
,
CapturePreviewViewDelegate
,
CaptureSessionDelegate
{
class
ViewController
:
UIViewController
,
CapturePreviewViewDelegate
,
CaptureSessionDelegate
{
private
lazy
var
navigationBarView
:
NavigationBarView
=
NavigationBarView
()
private
lazy
var
navigationBarView
:
NavigationBarView
=
NavigationBarView
()
private
lazy
var
captureView
:
CaptureView
=
CaptureView
()
private
lazy
var
captureView
:
CaptureView
=
CaptureView
()
...
@@ -30,6 +35,8 @@ class ViewController: UIViewController, CapturePreviewViewDelegate, CaptureSessi
...
@@ -30,6 +35,8 @@ class ViewController: UIViewController, CapturePreviewViewDelegate, CaptureSessi
private
lazy
var
flashButton
:
FlatButton
=
FlatButton
()
private
lazy
var
flashButton
:
FlatButton
=
FlatButton
()
private
lazy
var
closeButton
:
FlatButton
=
FlatButton
()
private
lazy
var
closeButton
:
FlatButton
=
FlatButton
()
private
lazy
var
captureMode
:
CaptureMode
=
.
Photo
override
func
viewDidLoad
()
{
override
func
viewDidLoad
()
{
super
.
viewDidLoad
()
super
.
viewDidLoad
()
prepareView
()
prepareView
()
...
@@ -72,7 +79,7 @@ class ViewController: UIViewController, CapturePreviewViewDelegate, CaptureSessi
...
@@ -72,7 +79,7 @@ class ViewController: UIViewController, CapturePreviewViewDelegate, CaptureSessi
captureButton
.
pulseFill
=
true
captureButton
.
pulseFill
=
true
captureButton
.
backgroundColor
=
MaterialColor
.
blue
.
darken1
.
colorWithAlphaComponent
(
0.3
)
captureButton
.
backgroundColor
=
MaterialColor
.
blue
.
darken1
.
colorWithAlphaComponent
(
0.3
)
captureButton
.
borderWidth
=
.
Border2
captureButton
.
borderWidth
=
.
Border2
captureButton
.
borderColor
=
MaterialColor
.
grey
.
darken1
captureButton
.
borderColor
=
MaterialColor
.
white
captureButton
.
shadowDepth
=
.
None
captureButton
.
shadowDepth
=
.
None
captureButton
.
addTarget
(
self
,
action
:
"handleCaptureButton:"
,
forControlEvents
:
.
TouchUpInside
)
captureButton
.
addTarget
(
self
,
action
:
"handleCaptureButton:"
,
forControlEvents
:
.
TouchUpInside
)
...
@@ -167,10 +174,14 @@ class ViewController: UIViewController, CapturePreviewViewDelegate, CaptureSessi
...
@@ -167,10 +174,14 @@ class ViewController: UIViewController, CapturePreviewViewDelegate, CaptureSessi
:name: handleCaptureButton
:name: handleCaptureButton
*/
*/
internal
func
handleCaptureButton
(
button
:
UIButton
)
{
internal
func
handleCaptureButton
(
button
:
UIButton
)
{
if
captureView
.
captureSession
.
isRecording
{
if
.
Photo
==
captureMode
{
captureView
.
captureSession
.
stopRecording
()
captureView
.
captureSession
.
captureStillImage
()
}
else
{
}
else
if
.
Video
==
captureMode
{
captureView
.
captureSession
.
startRecording
()
if
captureView
.
captureSession
.
isRecording
{
captureView
.
captureSession
.
stopRecording
()
}
else
{
captureView
.
captureSession
.
startRecording
()
}
}
}
}
}
...
@@ -219,6 +230,7 @@ class ViewController: UIViewController, CapturePreviewViewDelegate, CaptureSessi
...
@@ -219,6 +230,7 @@ class ViewController: UIViewController, CapturePreviewViewDelegate, CaptureSessi
*/
*/
func
handleCameraButton
(
button
:
UIButton
)
{
func
handleCameraButton
(
button
:
UIButton
)
{
captureButton
.
backgroundColor
=
MaterialColor
.
blue
.
darken1
.
colorWithAlphaComponent
(
0.3
)
captureButton
.
backgroundColor
=
MaterialColor
.
blue
.
darken1
.
colorWithAlphaComponent
(
0.3
)
captureMode
=
.
Photo
}
}
/**
/**
...
@@ -226,6 +238,7 @@ class ViewController: UIViewController, CapturePreviewViewDelegate, CaptureSessi
...
@@ -226,6 +238,7 @@ class ViewController: UIViewController, CapturePreviewViewDelegate, CaptureSessi
*/
*/
func
handleVideoButton
(
button
:
UIButton
)
{
func
handleVideoButton
(
button
:
UIButton
)
{
captureButton
.
backgroundColor
=
MaterialColor
.
red
.
darken1
.
colorWithAlphaComponent
(
0.3
)
captureButton
.
backgroundColor
=
MaterialColor
.
red
.
darken1
.
colorWithAlphaComponent
(
0.3
)
captureMode
=
.
Video
}
}
/**
/**
...
@@ -253,14 +266,14 @@ class ViewController: UIViewController, CapturePreviewViewDelegate, CaptureSessi
...
@@ -253,14 +266,14 @@ class ViewController: UIViewController, CapturePreviewViewDelegate, CaptureSessi
:name: captureDidStartRecordingToOutputFileAtURL
:name: captureDidStartRecordingToOutputFileAtURL
*/
*/
func
captureDidStartRecordingToOutputFileAtURL
(
capture
:
CaptureSession
,
captureOutput
:
AVCaptureFileOutput
,
fileURL
:
NSURL
,
fromConnections
connections
:
[
AnyObject
])
{
func
captureDidStartRecordingToOutputFileAtURL
(
capture
:
CaptureSession
,
captureOutput
:
AVCaptureFileOutput
,
fileURL
:
NSURL
,
fromConnections
connections
:
[
AnyObject
])
{
print
(
"Capture Started Recording"
)
print
(
"Capture Started Recording
\(
fileURL
)
"
)
}
}
/**
/**
:name: captureDidFinishRecordingToOutputFileAtURL
:name: captureDidFinishRecordingToOutputFileAtURL
*/
*/
func
captureDidFinishRecordingToOutputFileAtURL
(
capture
:
CaptureSession
,
captureOutput
:
AVCaptureFileOutput
,
outputFileURL
:
NSURL
,
fromConnections
connections
:
[
AnyObject
],
error
:
NSError
!
)
{
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
...
@@ -22,7 +22,18 @@ import AVFoundation
private
var
CaptureSessionAdjustingExposureContext
:
UInt8
=
1
private
var
CaptureSessionAdjustingExposureContext
:
UInt8
=
1
public
enum
CaptureSessionPreset
{
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 {
...
@@ -30,8 +41,34 @@ public enum CaptureSessionPreset {
*/
*/
public
func
CaptureSessionPresetToString
(
preset
:
CaptureSessionPreset
)
->
String
{
public
func
CaptureSessionPresetToString
(
preset
:
CaptureSessionPreset
)
->
String
{
switch
preset
{
switch
preset
{
case
.
High
:
case
.
PresetPhoto
:
return
AVCaptureSessionPresetPhoto
case
.
PresetHigh
:
return
AVCaptureSessionPresetHigh
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 {
...
@@ -101,6 +138,11 @@ public class CaptureSession : NSObject, AVCaptureFileOutputRecordingDelegate {
private
lazy
var
movieOutput
:
AVCaptureMovieFileOutput
=
AVCaptureMovieFileOutput
()
private
lazy
var
movieOutput
:
AVCaptureMovieFileOutput
=
AVCaptureMovieFileOutput
()
/**
/**
:name: movieOutputURL
*/
private
var
movieOutputURL
:
NSURL
?
/**
:name: session
:name: session
*/
*/
internal
lazy
var
session
:
AVCaptureSession
=
AVCaptureSession
()
internal
lazy
var
session
:
AVCaptureSession
=
AVCaptureSession
()
...
@@ -116,11 +158,6 @@ public class CaptureSession : NSObject, AVCaptureFileOutputRecordingDelegate {
...
@@ -116,11 +158,6 @@ public class CaptureSession : NSObject, AVCaptureFileOutputRecordingDelegate {
public
private(set)
lazy
var
isRecording
:
Bool
=
false
public
private(set)
lazy
var
isRecording
:
Bool
=
false
/**
/**
:name: movieOutputURL
*/
public
private(set)
var
movieOutputURL
:
NSURL
?
/**
:name: activeCamera
:name: activeCamera
*/
*/
public
var
activeCamera
:
AVCaptureDevice
?
{
public
var
activeCamera
:
AVCaptureDevice
?
{
...
@@ -131,7 +168,7 @@ public class CaptureSession : NSObject, AVCaptureFileOutputRecordingDelegate {
...
@@ -131,7 +168,7 @@ public class CaptureSession : NSObject, AVCaptureFileOutputRecordingDelegate {
:name: init
:name: init
*/
*/
public
override
init
()
{
public
override
init
()
{
sessionPreset
=
.
High
sessionPreset
=
.
Preset
High
super
.
init
()
super
.
init
()
prepareSession
()
prepareSession
()
}
}
...
@@ -630,7 +667,10 @@ public class CaptureSession : NSObject, AVCaptureFileOutputRecordingDelegate {
...
@@ -630,7 +667,10 @@ public class CaptureSession : NSObject, AVCaptureFileOutputRecordingDelegate {
private
func
uniqueURL
()
->
NSURL
?
{
private
func
uniqueURL
()
->
NSURL
?
{
do
{
do
{
let
directory
:
NSURL
=
try
NSFileManager
.
defaultManager
()
.
URLForDirectory
(
.
DocumentDirectory
,
inDomain
:
.
UserDomainMask
,
appropriateForURL
:
nil
,
create
:
true
)
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
{
}
catch
let
e
as
NSError
{
delegate
?
.
captureCreateMovieFileFailedWithError
?(
self
,
error
:
e
)
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