 1. Percentage

How would I get the percentage played of a file with the directshow object? I know you can get the current position and total duration. So what would the expression be? I thought: GetPosition( "Direct Show" )/GetDuration( "Direct Show" )*100. But that doesn't seem to work :s  Reply With Quote

2. Re: Percentage

LOL

I was just crafting a little bit, and I finally got it

(GetDuration( "Direct Show" )-(GetDuration( "Direct Show" )-GetPosition( "Direct Show" )))/(GetDuration( "Direct Show" )/100)

There must be an easier way!!!  Reply With Quote

3. Re: Percentage

(GetPosition( "Direct Show" )/GetDuration( "Direct Show" ))*100.

You were dividing by 100, instead of multiplying by 100.

Greetings!  Reply With Quote

4. Re: Percentage

But he posted exactly that what you posted. And I tested that, it doesn't work.  Reply With Quote

5. Re: Percentage

For it to work, the counter must be a floating point number. Change the *100 to *100.00 and see if that works.  Reply With Quote

6. Re: Percentage

(GetPosition( "Direct Show" )*100)/GetDuration( "Direct Show" )

Plooscva  Reply With Quote

7. Re: Percentage

They should all work, just that looki's version is rather lengthened.

PERCENTAGE = VALUE / TOTAL

because we display percentages as a fraction of 100 then you just x by 100. The problem with doing this after the division is that it creates a decimal number that might be rounded at somestage.

% = (VALUE*100)/TOTAL

Gives a vaild percentage.
Lets have a look at Looki's example:

[color:green]% = (x-(x-y))/(x/100)[/color]

We can use a few identities (equations that are always true) to simplify this:

Firstly,

(x-(x-y)) == y

because if x-y = z you can rearrange this to make x-z = y

[color:green]% = y/(x/100)[/color]

Secondly,

y/(x/100) == (y*100)/x

e.g. 2*100/4 = 200/4 = 50 = 2/0.04 = 2/(4/100)

...so basically they're the same thing  Reply With Quote

8. Re: Percentage

Yes, multiply first rather than after the division (or convert to floating point) to avoid rounding errors.  Reply With Quote Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•