Reputation: 77
I'm using the MediaPlayerElement in a UWP app. I'm hoping to convert the displayed value from TimeElapsedElement and TimeRemainingElement in frames rather then seconds.
So currently the value I recieve is: hh:mm:ss:ff (ff fractions of a second)
The value I would like to have is: FFFFF (the number of total frames elapsed thus far) or a standard time-code value such as hh:mm:ss:FF (FF being frames elapsed in the current second)
It seems I'm unable to access and modify the TimeElapsed and TimeRemaining elements in particular but wondering if those values would be suitable for some kind of conversion that gets the frame-rate of the media playing and converts the value into frames.
Alternatively, I was wondering if I could use MediaPlayer.PlaybackSession.Position to create my own variable that is in frames rather then seconds and display that value instead. I imagine there is some conversion occurring already that takes the framerate of the loaded media.
Wondering what method you would recommend and if you could point me in the direction of any resources for time to frames conversion in c#? Thanks for any help you can provide!
Upvotes: 1
Views: 1056
Reputation: 7727
Currently MediaPlayerElement
does not provide information on how many frames have passed, time is a more general expression.
If you need to get how many frames are currently passing, you need to do some calculations:
Frame rate * Play time
How to get frame rate
List<string> videoProperties = new List<string>();
videoProperties.Add("System.Video.FrameRate");
IDictionary<string, object> retrieveProperties = await file.Properties.RetrievePropertiesAsync(videoProperties);
double frameRate = ((uint)retrieveProperties["System.Video.FrameRate"])/1000.0;
How to get past frames
var sec = MyPlayer.MediaPlayer.PlaybackSession.Position.TotalSeconds;
var frameCounts = sec * frameRate;
In most situation it is applicable, but this can only be used as a reference value. Because the frame rate of some videos is not fixed.
Thanks.
Upvotes: 1