Threads

5 posts / 0 new
Last post
anol
anol's picture
Offline
Mobile Wizard
Joined: 11 Dec 2009
Posts:
Threads

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?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

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?

carloparodo
carloparodo's picture
Offline
Joined: 10 Dec 2010
Posts:

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() != Innocent
{
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?

Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

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.

carloparodo
carloparodo's picture
Offline
Joined: 10 Dec 2010
Posts:

Sam thank you very much!
So it all works.