Results 1 to 1 of 1
- 04-27-2011, 08:25 AM #1
Member
- Join Date
- Apr 2011
- Posts
- 4
- Rep Power
- 0
Metronom app - problem with threading
Hello,
I have some kind of problem with my metromom application made in j2me. So, without threading this application have sometimes slowdowns, ofcourse this is not acceptable. So I decided to make some threading in this application, but I done something wrong, because application play "Tick" only once. And then is Silence, without threading application was working fine. Here is my source code:
fragment of class "Designer" where i start timer:
class "MetronomeTimerEvent" where i specify a new thread and some kind of things.Java Code:protected void startMetronome() { calculateInterval = 60000/(howManyBpm); startTimerEvents = new MetronomeTimerEvent(metrum); timer.schedule(startTimerEvents, 1000, calculateInterval); }
Class "PlayTik" where I play a sounds.Java Code:import java.util.TimerTask; /** * @author Damian */ public class MetronomeTimerEvent extends TimerTask{ public MetronomeTimerEvent(byte metr) { i = 0; metrum = metr; playThis = new PlayTik(); playThisStart = new Thread(playThis); } public void run() { playThis.changeVariableI(i); playThisStart.start(); i++; if(i==metrum) i=0; } private byte i; private PlayTik playThis; private Thread playThisStart; public byte metrum; }
Hope you help me find a solution of this problem! : )Java Code:import javax.microedition.media.control.*; import javax.microedition.media.*; /** * @author Damian */ public class PlayTik implements Runnable { public PlayTik() { try { playTick = Manager.createPlayer(getClass().getResourceAsStream("/1.wav"), "audio/x-wav"); playTick.realize(); playTick.prefetch(); } catch(Exception ex) { } VolumeControl volumeV = (VolumeControl)playTick.getControl("VolumeControl"); volumeV.setLevel(99); try { playTock = Manager.createPlayer(getClass().getResourceAsStream("/2.wav"), "audio/x-wav"); playTock.realize(); playTock.prefetch(); } catch(Exception ex) { } VolumeControl volumeV1 = (VolumeControl)playTock.getControl("VolumeControl"); volumeV1.setLevel(99); } public void run() { testPlay(); } public int testPlay() { try { if(i==0) { playTock.start(); return 0; } else { playTick.start(); return 0; } }catch(Exception ex) { return 1; } } public void changeVariableI(byte changedVariable) { i = changedVariable; } public byte i; private Player playTick; private Player playTock; }
Similar Threads
-
multi-threading problem
By imorio in forum New To JavaReplies: 1Last Post: 04-25-2011, 06:52 PM -
Threading problem
By Andyj in forum Threads and SynchronizationReplies: 3Last Post: 12-05-2010, 09:27 PM -
Problem in Multi threading.
By Chetans in forum Advanced JavaReplies: 3Last Post: 03-23-2010, 04:42 PM -
Getting problem in threading in JAVA
By Chetans in forum Threads and SynchronizationReplies: 3Last Post: 03-19-2010, 07:49 AM -
Problem in threading
By saurabh in forum Threads and SynchronizationReplies: 6Last Post: 12-01-2008, 08:16 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks