Convert TMediaPlayer->Duration to min:sec (FMX)

  

I’m working with the TMediaPlayer1 control in an FMX app using C++ Builder 10.2 Version 25.0.29899.2631. The code below runs fine in Win32 and gives the expected result after loading an mp3 file that is 35 minutes, 16 seconds long.

When i run this same code targeting iOS i get the following error:

[bcciosarm64 Error] Unit1.cpp(337): use of overloaded operator ‘/’ is ambiguous (with operand types ‘Fmx::Media::TMediaTime’ and ‘int’)

Here is my code that takes the TMediaPlayer1->Duration and converts it to min:sec,

UnicodeString S = System::Ioutils::TPath::Combine(System::Ioutils::TPath::GetDocumentsPath(),”43506.mp3″);
if (FileExists(S)) {
MediaPlayer1->FileName = S;
int sec = MediaPlayer1->Duration / 10000000; // <– this is problem line
int min = sec / 60;
sec = sec – (60 * min);
lblEndTime->Text = IntToStr(min) + “:” + IntToStr(sec);
}

How should i be doing that division?

UPDATE 1: I fumbled around and figured out how to see the values with this code below. When i run on Win32 i get 21169987500 for the Duration (35 min, 16 seconds) and i get 10000000 for MediaTimeScale – both correct. When i run on iOS i get 0 for Duration and 10000000 for MediaTimeScale. But, if i start the audio playing (e.g. MediaPlayer1->Play();) first and THEN run those 2 showmessages i get the correct result for Duration.

MediaPlayer1->FileName = S; // load the mp3
ShowMessage(IntToStr((__int64) Form1->MediaPlayer1->Media->Duration));
ShowMessage(IntToStr((__int64) MediaTimeScale));

It looks like the Duration does not get set on iOS until the audio actually starts playing. I tried a 5 second delay after setting MediaPlayer1->Filename but that doesn’t work. I tried a MediaPlayer1->Play(); followed by MediaPlayer->Stop(); but that didn’t work either.

Why isn’t Duration set when the FileName is assigned? I’d like to show the Duration before the user ever starts playing the audio.

Comments are closed.