piemonte/PBJVideoPlayer

How to get current duration ? Thx for support

paneaktae opened this issue · 6 comments

Thx for support. :)

natan commented

@paneaktae Are you asking for the current time of the player (ie. "3 seconds into 10 second video") or total duration of the video (ie "10 seconds")?

I could use access to both. Having access to AVPlayerItem's duration and AVPlayer's currentTime would be ideal to construct a progress bar or seeking actions.

natan commented

@ataranlen I believe you can currently get those values by retrieving the AVPlayerItem with videoPlayerController.view.player, right?

You cannot, as both the player and playerItem aren't accessible outside the scope of the pod.

natan commented

@ataranlen Yes, they are. This worked for me just now in a test project:

#import <PBJVideoPlayer/PBJVideoPlayer.h>

…
AVPlayer *player = [(PBJVideoView *)videoPlayerController.view player];
AVPlayerItem *playerItem = player.currentItem;
NSLog(@"duration: %@, currentTime: %@", CMTimeCopyDescription(NULL, playerItem.duration), CMTimeCopyDescription(NULL, playerItem.currentTime));
…

Ah wasn't thinking about casting it. @paneaktae You should be able to use the above to get the duration.