Guest User

Untitled

a guest
Nov 22nd, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.78 KB | None | 0 0
  1. AVURLAsset* videoAsset = [AVURLAsset URLAssetWithURL:url options:nil];
  2. CMTime videoDuration = videoAsset.duration;
  3. float videoDurationSeconds = CMTimeGetSeconds(videoDuration);
  4.  
  5. > `
  6. // First, create NSDate object using
  7. NSDate* d = [[NSDate alloc] initWithTimeIntervalSinceNow:seconds];
  8. // Then specify output format
  9. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"HH:mm:ss"];
  10. // And get output with
  11. NSString* result = [dateFormatter stringWithDate:d];`
  12.  
  13. AVURLAsset *videoAVURLAsset = [AVURLAsset assetWithURL:url];
  14. CMTime durationV = videoAVURLAsset.duration;
  15.  
  16. NSUInteger dTotalSeconds = CMTimeGetSeconds(durationV);
  17.  
  18. NSUInteger dHours = floor(dTotalSeconds / 3600);
  19. NSUInteger dMinutes = floor(dTotalSeconds % 3600 / 60);
  20. NSUInteger dSeconds = floor(dTotalSeconds % 3600 % 60);
  21.  
  22. NSString *videoDurationText = [NSString stringWithFormat:@"%i:%02i:%02i",dHours, dMinutes, dSeconds];
  23.  
  24. NSString *timeDesc = (NSString *)CMTimeCopyDescription(NULL, self.player.currentTime);
  25. NSLog(@"Description of currentTime: %@", timeDesc);
  26.  
  27. NSString *timeDesc = (NSString *)CFBridgingRelease(CMTimeCopyDescription(NULL, self.player.currentTime));
  28. NSLog(@"Description of currentTime: %@", timeDesc);
  29.  
  30. AVURLAsset* videoAsset = [AVURLAsset URLAssetWithURL:url options:nil];
  31. CMTime videoDuration = videoAsset.duration;
  32. float videoDurationSeconds = CMTimeGetSeconds(videoDuration);
  33.  
  34. NSDate* date = [NSDate dateWithTimeIntervalSince1970:videoDurationSeconds];
  35. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  36. [dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];
  37. [dateFormatter setDateFormat:@"HH:mm:ss"]; //you can vary the date string. Ex: "mm:ss"
  38. NSString* result = [dateFormatter stringFromDate:date];
  39.  
  40. import CoreMedia
  41.  
  42. extension CMTime {
  43. var durationText:String {
  44. let totalSeconds = CMTimeGetSeconds(self)
  45. let hours:Int = Int(totalSeconds / 3600)
  46. let minutes:Int = Int(totalSeconds % 3600 / 60)
  47. let seconds:Int = Int(totalSeconds % 60)
  48.  
  49. if hours > 0 {
  50. return String(format: "%i:%02i:%02i", hours, minutes, seconds)
  51. } else {
  52. return String(format: "%02i:%02i", minutes, seconds)
  53. }
  54. }
  55. }
  56.  
  57. videoPlayer?.addPeriodicTimeObserverForInterval(CMTime(seconds: 1, preferredTimescale: 1), queue: dispatch_get_main_queue()) { time in
  58. print(time.durationText)
  59. }
  60.  
  61. NSLog(@"seconds = %f", CMTimeGetSeconds(cmTime));
  62.  
  63. let time = kCMTimeZero
  64. let timeString = time.toString()
  65.  
  66. extension CMTime {
  67. var durationText:String {
  68. let totalSeconds = CMTimeGetSeconds(self)
  69. let hours:Int = Int(totalSeconds / 3600)
  70. let minutes:Int = Int(totalSeconds.truncatingRemainder(dividingBy: 3600) / 60)
  71. let seconds:Int = Int(totalSeconds.truncatingRemainder(dividingBy: 60))
  72.  
  73. if hours > 0 {
  74. return String(format: "%i:%02i:%02i", hours, minutes, seconds)
  75. } else {
  76. return String(format: "%02i:%02i", minutes, seconds)
  77. }
  78. }
  79. }
  80.  
  81. func updateRecordingTimeLabel()
  82. {
  83.  
  84. // Result Output = MM:SS(01:23)
  85. let cmTime = videoFileOutput.recordedDuration
  86. var durationInSeconds = Int(CMTimeGetSeconds(cmTime))
  87. let durationInMinutes = Int(CMTimeGetSeconds(cmTime)/60)
  88. var strDuMin = String(durationInMinutes)
  89.  
  90. durationInSeconds = durationInSeconds-(60*durationInMinutes)
  91. var strDuSec = String(durationInSeconds)
  92.  
  93. if durationInSeconds < 10
  94. {
  95. strDuSec = "0"+strDuSec
  96. }
  97. if durationInMinutes < 10
  98. {
  99. strDuMin = "0"+strDuMin
  100. }
  101. // Update UILabel text
  102. lbl_Time.text = strDuMin+":"+strDuSec
  103. }
Add Comment
Please, Sign In to add comment