Results 1 to 1 of 1
  1. #1
    cartoon_20 is offline Member
    Join Date
    Apr 2010
    Rep Power

    Default [Solved]RecordControl commit() method works only once

    I'm writing midlet that captures sound from microphone. Problem is after starting second recording. I specified record limit with setRecordSizeLimit(N) function, but there is no answer from RecordControl, recording still continues.

    Here's initialization the first recording:
    Java Code:
                    p= Manager.createPlayer("capture://audio");
                    rc= (RecordControl)p.getControl("RecordControl");
                    if(rc == null)
                        throw new IOException("Can't get record control to manage data flow");
                    nbos= new NotifyingByteArrayOS(bundleSize, this, bundleSize);
                    if(nbos == null)
                        throw new IOException("Can't initialize data stream");
                try {
                     if(this.p.getState() != this.p.STARTED)
                } catch (MediaException ex) {
                     throw new MediaException("Can't start recording.");

    Here is a class that extends ByteArrayOutputStream, and when appropriate number of byte's been written to stream calls notifyMe() function:
    Java Code:
    public class NotifyingByteArrayOS extends ByteArrayOutputStream {
        protected int notifySize;
        protected Notifiable notify= null;
        public NotifyingByteArrayOS(int notifySize, Notifiable notify, int capacity) {
                if(notifySize < 1)
                    throw new IllegalArgumentException("notifySize can not be less than 0");
                this.notifySize= notifySize;
                this.notify= notify;
        public void write(byte[] b, int off, int len){
            super.write(b, off, len);
        public void write(byte[] b) throws IOException{
        public void write(byte b){
        private void checkCountAndNotify(){
             if(this.count >= this.notifySize)

    here is notifyMe method that initializes and starts subsequent recording:
    Java Code:
    public void notifyMe(){
            System.out.println(N + " bytes has been written");
            //if(this.rn != null)

    notifyMe is reached only once, but it should be called after each 512 bytes written to stream. How to record several times? Any ideas?

    I've found another way. I've placed notifyMe method's code to playerUpdate method (PlayerListener.RECORD_STOPPED event). And now it works. Maybe the problem was that subsequent records was initiated before commit() method has finished its execution. Commit method was called when appropriate number of bytes was recorded. Commit method wrote sound bytes to the output stream, and a output steam's write method called my notifyMe() method. Inside notifyMe() I initiated next recording, and it was before commit() returned. But it's my explanation :)
    Last edited by cartoon_20; 11-01-2010 at 08:03 PM.

Similar Threads

  1. Replies: 9
    Last Post: 11-04-2011, 03:09 AM
  2. EntityManager.setFlushMode(COMMIT) Vs. Query.setFlushMode(COMMIT)
    By CatchSandeepVaid in forum Enterprise JavaBeans (EJB)
    Replies: 0
    Last Post: 12-15-2009, 05:07 PM
  3. commit
    By swati.jyoti in forum NetBeans
    Replies: 1
    Last Post: 07-24-2009, 05:33 PM
  4. Replies: 6
    Last Post: 03-11-2009, 04:38 PM
  5. how compareTo Method works
    By nanaji in forum Advanced Java
    Replies: 1
    Last Post: 06-22-2008, 07:40 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts