Alexander
Alexander

Reputation: 691

Calculate playback seconds in accelerated file

I have an original file. Then, I've accelerated it in X%. I need to calculate seconds in accelerated file. For example 5 second in original file = x second in accelerated file. This is my code:

 private static TimeSpan GetSpeedUpTime(double seconds)
        {
            var time = new TimeSpan(0, 0, (int)Math.Floor(seconds));
            int increaseSpeedValue;
            int.TryParse(ConfigurationManager.AppSettings["IncreaseSpeedValue"], out increaseSpeedValue);
            return new TimeSpan(0, 0, (int)Math.Floor(seconds * increaseSpeedValue / 100));
        }

I can't understand what am I doing wrong? I know that task is very simple... but can't resolve it during an hour...

Upvotes: 2

Views: 31

Answers (1)

Dawnkeeper
Dawnkeeper

Reputation: 2875

This increaseSpeedValue / 100 will be handled as integer division. See remarks section here. This sets your TimeSpan to wrong.

The solution would be to cast to (double) or simply write 100.0

Upvotes: 1

Related Questions