4

I am getting a exception when I am recording a audio in Nokia C1. Below is the following exception I am getting:

Error2:
javax.microediting.media.MediaException: MUS

Can anyone help me in removing this exception or where am I going wrong?

Below, I am providing my code in which I am getting this exception:

package video;

import javax.microedition.midlet.*;

import java.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.media.*;
import javax.microedition.media.control.*;

public class VoiceRecordMidlet extends MIDlet {

    private Display display;

    public void startApp() {
        display = Display.getDisplay(this);
        display.setCurrent(new VoiceRecordForm());
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
        notifyDestroyed();
    }
}

class VoiceRecordForm extends Form implements CommandListener {

    private StringItem message;
    private StringItem errormessage;
    private final Command record, play, end;
    private Player player;
    private byte[] recordedAudioArray = null;
    private RecordControl rc;
    private ByteArrayOutputStream output;

    public VoiceRecordForm() {
        super("Recording Audio");
        message = new StringItem("", "Select Record to start recording.");
        this.append(message);
        errormessage = new StringItem("", "");
        this.append(errormessage);
        record = new Command("Record", Command.SCREEN, 0);
        this.addCommand(record);
        play = new Command("Play", Command.SCREEN, 0);
        end = new Command("End", Command.SCREEN, 0);
        this.setCommandListener(this);
    }

    public void commandAction(Command comm, Displayable disp) {
        if (comm == record) {
            Thread t = new Thread() {

                public void run() {
                    try {

                        player = Manager.createPlayer("capture://audio");

                        player.realize();
                        rc = (RecordControl) player.getControl("RecordControl");
                        output = new ByteArrayOutputStream();
                        rc.setRecordStream(output);
                        rc.startRecord();
                        player.start();
                        removeCommand(record);
                        addCommand(end);


                    } catch (Exception e) {
                        errormessage.setLabel("Error1");
                        errormessage.setText(e.toString());
                    }
                }
            };

            t.start();

        } else if (comm == play) {
            try {

                ByteArrayInputStream recordedInputStream = new ByteArrayInputStream(recordedAudioArray);

                Player p2 = Manager.createPlayer(recordedInputStream, "audio/basic");

                **p2.prefetch();

                p2.start();**

            } catch (Exception e) {
                errormessage.setLabel("Error2");
                errormessage.setText(e.toString());
            }
        } else if (comm == end) {
            try {
                rc.stopRecord();
                removeCommand(end);
                addCommand(play);
                                rc.commit();
                recordedAudioArray = output.toByteArray();

                player.close();

            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    }
}
sam
  • 51
  • 5

1 Answers1

0

The only difference I can spot when comparing the recording part of your code with the recording part of one of my projects, is that I call player.start() before I call recordControl.startRecord()

player = Manager.createPlayer("capture://audio");
player.realize();
player.start();
recordControl = (RecordControl) player.getControl("RecordControl");
bos = new ByteArrayOutputStream();
recordControl.setRecordStream(bos);
recordControl.startRecord();

That works for me on Sony Ericsson phones.

I don't playback the audio though, so I don't know if that part of your code is causing the problem.

mr_lou
  • 1,910
  • 2
  • 14
  • 26