| Reply | « Previous Thread | Next Thread » |
|
Hi,
The code works fine on the WTK Emulator, but I just can't figure out why it wont work on the N95/Symbian Emulator or phone.. Can anyone please tell me what is wrong? Thx in advance! ******************App.java****************** package Project; import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class App extends MIDlet { Display display; Mixer mCanvas; public App() { } protected void startApp() { mCanvas = new Mixer("DJJLAGT"); display = Display.getDisplay(this); display.setCurrent(mCanvas); } protected void pauseApp() { System.out.println("pauseApp called..."); } protected void destroyApp(boolean unconditional) { mCanvas.stop(); System.out.println("destroyApp called..."); } } *********************END********************** ******************Mixer.java****************** package Project; import javax.microedition.midlet.*; import javax.microedition.lcdui.*; import javax.microedition.rms.*; import javax.microedition.media.*; import javax.microedition.media.control.*; import javax.microedition.media.protocol.*; import java.io.*; import java.util.*; public class Mixer extends Canvas { Player Audioplayer, Recordplayer; VolumeControl vctrl; RateControl rctrl; RecordControl record; public ByteArrayOutputStream OutputStream; private ByteArrayInputStream InputStream; private byte [] ByteStream; int volume = 100; int rate = 100000; public Mixer(String title){ System.out.println("Started..."); } public void paint(Graphics g) { g.setColor(0x00000000); g.fillRect(0, 0, getWidth(), getHeight()); g.setColor(0x00ffffff); g.fillRect(0, 20, volume, 10); } public void record() { try { Recordplayer = Manager.createPlayer("capture://audio?rate=3000&bits=16"); Recordplayer.realize(); vctrl = (VolumeControl) Recordplayer.getControl("VolumeControl"); vctrl.setLevel(0); record = (RecordControl) Recordplayer.getControl("RecordControl"); OutputStream = new ByteArrayOutputStream(); record.setRecordStream(OutputStream); Recordplayer.start(); record.startRecord(); System.out.println("Recording (max 20 sec.)"); Thread.currentThread().sleep(20000); if(ByteStream==null){ stoprecord(); } } catch (InterruptedException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } catch (MediaException ex) { ex.printStackTrace(); } } public void stoprecord() { try { record.commit(); Recordplayer.close(); System.out.println("Stopped Recording"); ByteStream = OutputStream.toByteArray(); } catch (IOException ex) { ex.printStackTrace(); } } public void play() { try { if(ByteStream!=null){ InputStream = new ByteArrayInputStream(ByteStream); Audioplayer = Manager.createPlayer(InputStream, "audio/x-wav"); Audioplayer.realize(); vctrl = (VolumeControl) Audioplayer.getControl("VolumeControl"); vctrl.setLevel(volume); rctrl = (RateControl) Audioplayer.getControl("RateControl"); rctrl.setRate(rate); Audioplayer.setLoopCount(-1); Audioplayer.start(); System.out.println("Playing"); } } catch (Exception e) { System.out.println(e.toString()); } } public void stop() { try { Audioplayer.deallocate(); Audioplayer.close(); System.out.println("Stopped"); } catch(Exception e) {} } public void keyPressed(int keyCode) { if(keyCode == KEY_NUM1) { play(); } if(keyCode == KEY_NUM2) { stop(); } if(keyCode == -4) { if(volume<100) { volume+=10; System.out.println(""+volume); vctrl.setLevel(volume); repaint(); } } if(keyCode == -3) { if(volume>0) { volume-=10; System.out.println(""+volume); vctrl.setLevel(volume); repaint(); } } if(keyCode == -2) { if(rate<300000) { rate+=10000; System.out.println(""+rate); rctrl.setRate(rate); } } if(keyCode == -1) { if(rate>0) { rate-=10000; System.out.println(""+rate); rctrl.setRate(rate); } } if(keyCode == KEY_POUND) { new Thread(new Runnable(){ public void run() { try{ record(); }catch(Exception e){} } }).start(); } if(keyCode == KEY_STAR) { new Thread(new Runnable(){ public void run() { try{ stoprecord(); }catch(Exception e){} } }).start(); } } } ******************END****************** |
| GamezMaster |
| View Public Profile |
| Find all posts by GamezMaster |
|
How does it not work? Do you get an exception or what?
Hartti |
|
No exception,
The program starts, and then does nothing.. nothing at all.. no matter what button I push (#, *, 1 or 2) It should start recording when I push #, yet, it does nothing.. |
| GamezMaster |
| View Public Profile |
| Find all posts by GamezMaster |
|
Hello GamezMaster,
Quote:
How about implementing a CommandListener with the Canvas object just to see if that makes any difference? Regards, r2j7 |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Thread | Thread Starter | Forum | Replies | Last Post |
|---|---|---|---|---|
| N95 8GB Uninstallation problems | juliand77 | Installation, Certification and Security | 2 | 2007-12-07 11:23 |
| Is the Battery Life on the N95 8GB Better than the N95? | brstlrovrs4life | General Discussion | 1 | 2007-12-03 01:04 |
| Audio capture and J2ME | mike.f.watson | Audio | 0 | 2005-08-05 13:42 |