17

I try to capture video:
https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/04_MediaCapture.html#//apple_ref/doc/uid/TP40010188-CH5-SW26

var maxDuration : CMTime = CMTimeMake(seconds, preferredTimeScale)
aMovieFileOutput.maxRecordedDuration = CMTimeMake(seconds, preferredTimeScale)

1 row have error: Use of module 'CMTime' as a type
2 row have error: Use of unresolved identifier 'CMTimeMake'

What I do wrong?

Andrew Skrypnik
  • 183
  • 1
  • 2
  • 10

1 Answers1

31

CMTime and CMTimeMake are defined in the "CoreMedia" module, therefore you have to

import CoreMedia

Then this compiles without problems:

let seconds : Int64 = 10
let preferredTimeScale : Int32 = 1
let aMovieFileOutput = AVCaptureMovieFileOutput()
let maxDuration : CMTime = CMTimeMake(seconds, preferredTimeScale)
aMovieFileOutput.maxRecordedDuration = maxDuration

Update for Swift 3:

let maxDuration = CMTime(seconds: Double(seconds), preferredTimescale: 1)
Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382
  • if `CMTimeMake` also receives seconds what is the difference with `CMTimeMakeWithSeconds`? and if `preferredTimeScale` is just the denominator in `CMTimeMake` it is not clear what is its purpose in `CMTimeMakeWithSeconds` – dashesy Sep 11 '15 at 01:29
  • 2
    @dashesy: `CMTimeMake(value, timescale)` returns a CMTime with the given value and timescale, representing seconds = value/timescale (compare for example http://stackoverflow.com/a/13001917/1187415). `CMTimeMakeWithSeconds(seconds, preferredTimeScale)` returns a CMTime where value and timescale are chosen such that seconds=value/timescale, and timescale is preferredTimeScale (or a fraction thereof in the case of an overflow). As an example `CMTimeMake(2, 10)` and `CMTimeMakeWithSeconds(0.2, 10)` give the same result. – Martin R Sep 11 '15 at 08:09