Results 1 to 1 of 1
- 04-05-2011, 03:31 PM #1
Member
- Join Date
- Feb 2011
- Posts
- 3
- Rep Power
- 0
Multiple audio files played at once?
This has been bugging me for a long time, I've been trying to create a Drum Machine app, but unfortunately, I have to wait for one sound to finish before another one will play. There is also a delay even if you simultaneously press one button. Is it possible to play two at once, or at least stop one sound to play another one when pressed? The midlet itself is slow anyway any optimisation tips?
There are 6 drumpad objects in the canvas.
Java Code:package com.rightgoodent.media.soundeditor; import javax.microedition.lcdui.Graphics; import javax.microedition.media.Manager; import javax.microedition.media.Player; public class DrumPad extends Thread { private int pad_x,pad_y,pad_width,pad_height,pad_firstx,pad_firsty; String fname; Player midiPlayer; DrumPad(int px,int py,int pw,int ph,String fn){ pad_x = px; pad_y = py; pad_width = pw; pad_height = ph; pad_firstx = px; pad_firsty = py; fname = fn; try { midiPlayer = Manager.createPlayer(getClass().getResourceAsStream("resources/"+ fname), "audio/midi"); midiPlayer.prefetch(); midiPlayer.realize(); } catch (Exception e) { System.err.println(e); } } public void pressEvent(int x, int y) { if (x>pad_x && x<(pad_x+pad_width)&& y>pad_y && y<(pad_y+pad_width)) { pad_x +=6; pad_y +=8; if (midiPlayer != null) { try { midiPlayer.setTimeBase(midiPlayer.getTimeBase()); midiPlayer.start(); Thread.sleep(50); midiPlayer.stop(); } catch (Exception e) { System.err.println(e); } } } } public void releaseEvent(int x, int y){ pad_x = pad_firstx; pad_y = pad_firsty; } public void paint (Graphics g){ g.fillRect(pad_x, pad_y, pad_width, pad_height); } }
Similar Threads
-
Audio files.
By sarah jain in forum NetworkingReplies: 1Last Post: 03-11-2011, 05:36 PM -
highlight word when audio is played
By Saran185 in forum AWT / SwingReplies: 4Last Post: 02-09-2011, 10:57 AM -
run multiple jar files by one click
By wallacetju in forum New To JavaReplies: 2Last Post: 02-06-2011, 07:20 AM -
run multiple jar files by one click
By wallacetju in forum Advanced JavaReplies: 0Last Post: 02-06-2011, 06:50 AM -
multiple class files
By nemesys571 in forum EclipseReplies: 0Last Post: 06-26-2008, 01:58 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks