MediaElement.NaturalDuration is less than the actual duration of the sound.

In some audio files, the value of MediaElement.NaturalDuration is less than the actual duration of the sound. When I open a file in Windows Media Player, the duration is correct (also when I look at the file properties). Although the value of the NaturalDuration property is incorrect, the sound is reproduced completely, but at some point the value of the Position property becomes larger than the value of the NaturalDuration property, which, as I understand it, should never happen.

I created a simple application to reproduce the problem: https://skydrive.live.com/redir?resid=ACF8BFD4384116CE!2908&authkey=!AG-wF6Ae-7EAYk8

The duration of the sound file used in the application is 00:02:54, but the value of the NaturalDuration property is 00:01:59.

Does anyone know why and if there is a workaround for this?

Thanks in advance for any help.

+4
source share
1 answer

Well, this is not an answer, but some results of a short investigation that give some clues as to why he behaves this way and where these numbers come from (2:58 and 1:59). First look at this topic: Calculating the length of MP3 frames in milliseconds Two things we will use from there:

1) Frame length (in ms) = (sampling per frame / sampling frequency (in Hz)) * 1000 and

Duration in second = Frame length (in ms) * Number of frames / 1000

2) There are some standards regarding the number of samples for different versions of MPEG: Samples per frame:

MPEG version 1

384, // Layer1 1152, // Layer2 1152 // Layer3 

MPEG version 2 and 2.5

  384, // Layer1 1152, // Layer2 576 // Layer3 

Now let's check in winamp what it says about file format information:

MPEG-2.5 Level 3

16 kbps, 2482 frames

Now, if you take frames = 2482 and samples per frame = 576 (MPEG-2.5 level 3), you will get a duration of 2:58. But it seems that for some reason, Silverlight and iTunes are using samples per frame = 384, which gives us 1:59. The next step may be to check the real values โ€‹โ€‹of the file headers, and if they are correct, and you can calculate the correct duration - well, than you could prepare some hack to get the duration separately (from the server, for example). But I'm sure there are some flaws in this file (inconsistent titles and content), and some players can handle this, others not.

+1
source

Source: https://habr.com/ru/post/1489716/


All Articles