Support for threads would be splendid! I realize that old phones probably won't support it but if a phone has this capability, why not expose it?
Threads
Yeah, its not that straightforward unfortunately. Old phones do support threads, as J2ME supports threads, but I think it is the management of the threads which is the issue. Instead of exposing user-created threads, we support a timer-based model. This means that you can create a class which will run asynchronously of your other code, using a timer to switch to its execution. Was there something specific you wanted to implement?
Hi Sam,
I'm trying to achieve a progress bar that indicates the remaining time when playing an audio file.
The idea is to create an empty string (in a Label) and then increase it by one character for every second that passes after the start of the audio file:
//**********************************************************************
maSoundPlay((RES_MP3), 0, maGetDataSize(RES_MP3));
int startTime = 0;
int currentTime = 0;
int count = 0;
int timeElap = 1000;
startTime = maGetMilliSecondCount();
while(maSoundIsPlaying() != 
{
currentTime = maGetMilliSecondCount();
if(currentTime - startTime >= timeElap)
{
caption += "o";
labelBis->setCaption(caption);
timeElap += 1000;
count++;
}
if(count == 39) //upper limit: the file audio is of 39sec.
break;
}
//********************************************************************************
This seems to work ... But the two processes (reproduction of audio files and changes the string) does not occur simultaneously. What happens in the while loop, you see everything at once, only after playing the audio file is finished.
I thought then to solve the problem with the synchronization of two threads ... However I do not think is the best solution.
Do you have any advice for me?
Yeah, use a timer. You will need a C++ project though. Create a class which will play the sound, but also supports the TimerListener interface. When you call maSoundPlay, start the timer. In runTimerEvent(), check that the sound is still playing, add a "o" and update the screen. If the sound has finished, stop the timer.
Sam thank you very much!
So it all works.