Hello. I'm loading a .ogg music that has 3 minutes and the getDuration() is returning a incorrect value for the duration.
sf::SoundBuffer sb;
sb.loadFromFile("file2.ogg");
std::cout << sb.getDuration().asMilliseconds() << '\n';
this is returning something like 23xxxms, ~23s.
This happens with other files too.
I made this code to get the percentage of played sound:
sf::Sound s(sb);
s.play();
double time = 100.0*s.getPlayingOffset().asMilliseconds()/(double)sb.getDuration().asMilliseconds();
And time get bigger than 100 after 23s :). So, appears that the sf::Sound getPlayingOffset() works great but something wrongs happens with the sf::SoundBuffer getDuration()
Music file: https://docs.google.com/file/d/0B87ZIbsLOhJ3NVA2OHp6cHFPQm8/edit?usp=sharing
**This is for a audio software. I know when use sf::Music..
Thanks.
Grégory
I can replicate this result with that file.
This is the exact code I tested with (Win32 console app in VS 2010):
#include "StdAfx.h"
#include <iostream>
#include <SFML/Audio.hpp>
int main(){
sf::SoundBuffer sb;
sb.loadFromFile("file2.ogg");
std::cout << sb.getDuration().asMilliseconds() << '\n';
sf::Sound s(sb);
s.play();
while(s.getStatus() == sf::Sound::Playing) {
sf::sleep(sf::seconds(10));
double time = 100.0*s.getPlayingOffset().asMilliseconds()/(double)sb.getDuration().asMilliseconds();
std::cout << time << " ";
}
std::cout << std::endl << "Done";
char c; std::cin >> c; //quick way to ensure the console stays open for a while
}
This is the console output I got:
(http://gyazo.com/8450fbf75a253414aac396725b546369.png)
So we nearly hit 2000% of a 23s file (according to these numbers) which implies a length of 7 and 2/3 minutes, which seems pretty close to the 7:42 that Media Player Classic gives me. So at least MPC gets the right length, which I guess means the file isn't corrupted?