Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- self.player.currentItem.asset.duration
- #import <AVFoundation/AVPlayer.h>
- #import <AVFoundation/AVPlayerItem.h>
- #import <AVFoundation/AVAsset.h>
- CMTime duration = self.player.currentItem.asset.duration;
- float seconds = CMTimeGetSeconds(duration);
- NSLog(@"duration: %.2f", seconds);
- AVFoundation
- CoreMedia
- self.player.currentItem.duration;
- if let duration = player.currentItem?.asset.duration {
- let seconds = CMTimeGetSeconds(duration)
- print(seconds)
- }
- - (CMTime)playerItemDuration
- {
- AVPlayerItem *thePlayerItem = [player currentItem];
- if (thePlayerItem.status == AVPlayerItemStatusReadyToPlay)
- {
- /*
- NOTE:
- Because of the dynamic nature of HTTP Live Streaming Media, the best practice
- for obtaining the duration of an AVPlayerItem object has changed in iOS 4.3.
- Prior to iOS 4.3, you would obtain the duration of a player item by fetching
- the value of the duration property of its associated AVAsset object. However,
- note that for HTTP Live Streaming Media the duration of a player item during
- any particular playback session may differ from the duration of its asset. For
- this reason a new key-value observable duration property has been defined on
- AVPlayerItem.
- See the AV Foundation Release Notes for iOS 4.3 for more information.
- */
- return([playerItem duration]);
- }
- return(kCMTimeInvalid);
- }
- float scrubberBarLocation = (scrubberBgImageView.frame.size.width / 100.0f) * [self moviePercentage];
- - (float)moviePercentage {
- CMTime t1 = [avPlayer currentTime];
- CMTime t2 = avPlayer.currentItem.asset.duration;
- float myCurrentTime = CMTimeGetSeconds(t1);
- float myDuration = CMTimeGetSeconds(t2);
- float percent = (myCurrentTime / myDuration)*100.0f;
- return percent;
- }
- - (void)updateVideoPercent:(float)thisPercent {
- CMTime t2 = avPlayer.currentItem.asset.duration;
- float myDuration = CMTimeGetSeconds(t2);
- float result = myDuration * thisPercent /100.0f;
- //NSLog(@"this result = %f",result); // debug
- CMTime seekTime = CMTimeMake(result, 1);
- [avPlayer seekToTime:seekTime];
- }
Add Comment
Please, Sign In to add comment