Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- AVURLAsset* videoAsset = [AVURLAsset URLAssetWithURL:url options:nil];
- CMTime videoDuration = videoAsset.duration;
- float videoDurationSeconds = CMTimeGetSeconds(videoDuration);
- > `
- // First, create NSDate object using
- NSDate* d = [[NSDate alloc] initWithTimeIntervalSinceNow:seconds];
- // Then specify output format
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"HH:mm:ss"];
- // And get output with
- NSString* result = [dateFormatter stringWithDate:d];`
- AVURLAsset *videoAVURLAsset = [AVURLAsset assetWithURL:url];
- CMTime durationV = videoAVURLAsset.duration;
- NSUInteger dTotalSeconds = CMTimeGetSeconds(durationV);
- NSUInteger dHours = floor(dTotalSeconds / 3600);
- NSUInteger dMinutes = floor(dTotalSeconds % 3600 / 60);
- NSUInteger dSeconds = floor(dTotalSeconds % 3600 % 60);
- NSString *videoDurationText = [NSString stringWithFormat:@"%i:%02i:%02i",dHours, dMinutes, dSeconds];
- NSString *timeDesc = (NSString *)CMTimeCopyDescription(NULL, self.player.currentTime);
- NSLog(@"Description of currentTime: %@", timeDesc);
- NSString *timeDesc = (NSString *)CFBridgingRelease(CMTimeCopyDescription(NULL, self.player.currentTime));
- NSLog(@"Description of currentTime: %@", timeDesc);
- AVURLAsset* videoAsset = [AVURLAsset URLAssetWithURL:url options:nil];
- CMTime videoDuration = videoAsset.duration;
- float videoDurationSeconds = CMTimeGetSeconds(videoDuration);
- NSDate* date = [NSDate dateWithTimeIntervalSince1970:videoDurationSeconds];
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
- [dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];
- [dateFormatter setDateFormat:@"HH:mm:ss"]; //you can vary the date string. Ex: "mm:ss"
- NSString* result = [dateFormatter stringFromDate:date];
- import CoreMedia
- extension CMTime {
- var durationText:String {
- let totalSeconds = CMTimeGetSeconds(self)
- let hours:Int = Int(totalSeconds / 3600)
- let minutes:Int = Int(totalSeconds % 3600 / 60)
- let seconds:Int = Int(totalSeconds % 60)
- if hours > 0 {
- return String(format: "%i:%02i:%02i", hours, minutes, seconds)
- } else {
- return String(format: "%02i:%02i", minutes, seconds)
- }
- }
- }
- videoPlayer?.addPeriodicTimeObserverForInterval(CMTime(seconds: 1, preferredTimescale: 1), queue: dispatch_get_main_queue()) { time in
- print(time.durationText)
- }
- NSLog(@"seconds = %f", CMTimeGetSeconds(cmTime));
- let time = kCMTimeZero
- let timeString = time.toString()
- extension CMTime {
- var durationText:String {
- let totalSeconds = CMTimeGetSeconds(self)
- let hours:Int = Int(totalSeconds / 3600)
- let minutes:Int = Int(totalSeconds.truncatingRemainder(dividingBy: 3600) / 60)
- let seconds:Int = Int(totalSeconds.truncatingRemainder(dividingBy: 60))
- if hours > 0 {
- return String(format: "%i:%02i:%02i", hours, minutes, seconds)
- } else {
- return String(format: "%02i:%02i", minutes, seconds)
- }
- }
- }
- func updateRecordingTimeLabel()
- {
- // Result Output = MM:SS(01:23)
- let cmTime = videoFileOutput.recordedDuration
- var durationInSeconds = Int(CMTimeGetSeconds(cmTime))
- let durationInMinutes = Int(CMTimeGetSeconds(cmTime)/60)
- var strDuMin = String(durationInMinutes)
- durationInSeconds = durationInSeconds-(60*durationInMinutes)
- var strDuSec = String(durationInSeconds)
- if durationInSeconds < 10
- {
- strDuSec = "0"+strDuSec
- }
- if durationInMinutes < 10
- {
- strDuMin = "0"+strDuMin
- }
- // Update UILabel text
- lbl_Time.text = strDuMin+":"+strDuSec
- }
Add Comment
Please, Sign In to add comment