Guest User

Untitled

a guest
Jan 10th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. self.player.currentItem.asset.duration
  2.  
  3. #import <AVFoundation/AVPlayer.h>
  4. #import <AVFoundation/AVPlayerItem.h>
  5. #import <AVFoundation/AVAsset.h>
  6.  
  7. CMTime duration = self.player.currentItem.asset.duration;
  8. float seconds = CMTimeGetSeconds(duration);
  9. NSLog(@"duration: %.2f", seconds);
  10.  
  11. AVFoundation
  12. CoreMedia
  13.  
  14. self.player.currentItem.duration;
  15.  
  16. if let duration = player.currentItem?.asset.duration {
  17. let seconds = CMTimeGetSeconds(duration)
  18. print(seconds)
  19. }
  20.  
  21. - (CMTime)playerItemDuration
  22. {
  23. AVPlayerItem *thePlayerItem = [player currentItem];
  24. if (thePlayerItem.status == AVPlayerItemStatusReadyToPlay)
  25. {
  26. /*
  27. NOTE:
  28. Because of the dynamic nature of HTTP Live Streaming Media, the best practice
  29. for obtaining the duration of an AVPlayerItem object has changed in iOS 4.3.
  30. Prior to iOS 4.3, you would obtain the duration of a player item by fetching
  31. the value of the duration property of its associated AVAsset object. However,
  32. note that for HTTP Live Streaming Media the duration of a player item during
  33. any particular playback session may differ from the duration of its asset. For
  34. this reason a new key-value observable duration property has been defined on
  35. AVPlayerItem.
  36.  
  37. See the AV Foundation Release Notes for iOS 4.3 for more information.
  38. */
  39.  
  40. return([playerItem duration]);
  41. }
  42.  
  43. return(kCMTimeInvalid);
  44. }
  45.  
  46. float scrubberBarLocation = (scrubberBgImageView.frame.size.width / 100.0f) * [self moviePercentage];
  47.  
  48.  
  49. - (float)moviePercentage {
  50.  
  51. CMTime t1 = [avPlayer currentTime];
  52. CMTime t2 = avPlayer.currentItem.asset.duration;
  53.  
  54. float myCurrentTime = CMTimeGetSeconds(t1);
  55. float myDuration = CMTimeGetSeconds(t2);
  56.  
  57. float percent = (myCurrentTime / myDuration)*100.0f;
  58. return percent;
  59.  
  60. }
  61.  
  62. - (void)updateVideoPercent:(float)thisPercent {
  63.  
  64. CMTime t2 = avPlayer.currentItem.asset.duration;
  65. float myDuration = CMTimeGetSeconds(t2);
  66.  
  67. float result = myDuration * thisPercent /100.0f;
  68.  
  69. //NSLog(@"this result = %f",result); // debug
  70.  
  71. CMTime seekTime = CMTimeMake(result, 1);
  72.  
  73. [avPlayer seekToTime:seekTime];
  74.  
  75. }
Add Comment
Please, Sign In to add comment