| Reply | « Previous Thread | Next Thread » |
|
hi every one im using the 2.5 wireless toolkit and i tried to record voice in . wav & it did work ,but it want playback wat is recorded .
it just play .amr ,so can i record in .amr or trnscode wav to amr any one has an idea. hers my code if(c==playsong) try { InputStream is = getClass().getResourceAsStream("/audio/m.wav"); is.mark(is.available()); p = Manager.createPlayer(is, "audio/x-wav"); p.realize(); p.addPlayerListener(new Listener()); vc = (VolumeControl)p.getControl("VolumeControl"); if (vc != null) vc.setLevel(100); p.setMediaTime(5 * sec); p.prefetch(); // Non-blocking start p.start(); } catch (IOException ioe) {System.out.println("io exception"); } catch (MediaException me) {System.out.println(me.toString());} |
| manaljuwdat |
| View Public Profile |
| Find all posts by manaljuwdat |
|
Quote:
/* Sound capture Midlet with the data being stored/ Recorded in an Output Stream * And also muted while recording*/ //package hello; import javax.microedition.midlet.*; import javax.microedition.lcdui.*; import javax.microedition.io.*; import java.io.*; import javax.microedition.media.*; import javax.microedition.media.control.*; import javax.microedition.io.file.*; import java.util.Random; //------------------------------------------------------------------------------------------- class PlayerThread extends Thread implements PlayerListener{ InputStream is =null; String type = null; Player player=null; long startTime = 0; long startedTime=0; long stopTime=0; String fileName=null; public PlayerThread(InputStream is, String type ) { this.is = is; this.type=type; } public PlayerThread( String filename) { this.fileName=filename; } public void run() { try{ startTime=System.currentTimeMillis()/1000; // creating the player depending on which constructor has been used // if the constructor that takes a file name has been used the progressive download // functionality will be used. if(fileName==null) player = Manager.createPlayer(is, type ); else player = Manager.createPlayer(fileName); // registering the playerthread as a PlayerListener player.addPlayerListener(this); // Allocating the resources for the audio data player.realize(); // start the playback player.start(); }catch(Exception e){System.out.println(e.toString());} } public void playerUpdate(Player player,java.lang.String event,java.lang.Object eventData) { if (event.compareTo(PlayerListener.STARTED)==0 ) { startedTime=System.currentTimeMillis()/1000; System.out.println("player creation Time="+(startedTime-startTime)); } if (event.compareTo(PlayerListener.END_OF_MEDIA)==0 ) { stopTime=System.currentTimeMillis()/1000; System.out.println("playTime="+(stopTime-startTime)); // When the media has been played we close the player player.close(); } } } //----------------------------------------------------------------------------------------------------- /** * * @author 23049734 */ public class SoundRecTransmit extends MIDlet implements javax.microedition.lcdui.CommandListener, PlayerListener, Runnable { ByteArrayOutputStream outputStream =null; byte[] byteArray = null; String locator= "capture://audio"; Player player =null; Form form; TextField tb = null; Command recCommand, stopRecCommand, playCommand,exitCommand; Display display=null; VolumeControl vc; RecordControl rc=null; ChoiceGroup cg; boolean flags[] = new boolean[2]; /** Creates a new instance of HelloMidlet */ public SoundRecTransmit () { cg= new ChoiceGroup ("Record to", ChoiceGroup.EXCLUSIVE); //cg.append("file",null); cg.append("byteArray", null); //cg.setSelectedIndex(1, true); form = new Form("Audio Capture"); recCommand = new Command("record", Command.OK, 1); stopRecCommand = new Command("stop record", Command.OK, 1); playCommand = new Command("Play", Command.SCREEN, 2); exitCommand = new Command("Exit", Command.SCREEN, 2); tb = new TextField("SoundCapture", "info", 256, TextField.UNEDITABLE) ; form.addCommand(recCommand); form.addCommand(playCommand); form.addCommand(exitCommand); form.setCommandListener(this); form.append(tb); form.append(cg); } private void initialize() { } public void startApp() { if(display==null) display=Display.getDisplay(this); display.setCurrent(form); initialize(); } public void pauseApp() { } public void destroyApp(boolean unconditional) { } public void commandAction(Command c, Displayable s) { // Making a boolean vector to get the options from the choicegroup // boolean flags[] = new boolean[2]; //flags[0]=false; //flags[1]=false; //cg.getSelectedFlags(flags); if (c == recCommand) // start the recording { Thread test = new Thread(this); test.start(); } else if (c == stopRecCommand) // Stop the recording { System.out.println("StoprecCommand"); // Changing the stopCommand with recCommand form.removeCommand(stopRecCommand); form.addCommand(recCommand); System.out.println("Recorded Data is " ); try{ // stop recording rc.commit(); // and stop the playback from the microphone vc.setMute(false);//to mute player.close(); tb.setString("Recorder to byteArray stopped:"); } catch(Exception e){tb.setString(e.toString());} } else if (c == playCommand) // start the playback of the recorded audio { System.out.println("play from ByteArrayInputStream"); if(outputStream==null) return; // getting the ByteArray from the ByteArrayOutputStream byteArray = outputStream.toByteArray(); // Creating and starting the playback thread new PlayerThread(new ByteArrayInputStream(byteArray), "audio/X-wav" ).start(); tb.setString("Playing "); } else if (c == exitCommand) { notifyDestroyed(); } } public void playerUpdate(Player player,java.lang.String event,java.lang.Object eventData) { System.out.println("playerUpdate event="+event); } public void run() { System.out.println("recCommand"); tb.setString("Recorder started:"); // Changing the recCommand with the stopCommand form.removeCommand(recCommand); form.addCommand(stopRecCommand); try{ // creating the player from the file url enabling progressive download player = Manager.createPlayer(locator); // adding playerListenter player.addPlayerListener(this); // allocating the resources from the microphone player.realize(); // Getting the ReocrdControll so we can record the output from the player rc = (RecordControl)player.getControl("RecordControl"); // rc.setRecordSizeLimit(60000); } catch(Exception er){tb.setString(er.toString());} outputStream = null; outputStream = new ByteArrayOutputStream(); if(rc==null) System.out.println("rc==null"); // setting the record location to the outputstream rc.setRecordStream(outputStream); try{ // start recording rc.startRecord(); vc = (VolumeControl) player.getControl("VolumeControl"); // start to play the sound from the microphone player.start(); vc.setMute(true);//to mute. } catch(Exception e){tb.setString(e.toString());} } } with regards, Khalandar Pasha N (khalandar_p@yahoo.co.in) |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Thread | Thread Starter | Forum | Replies | Last Post |
|---|---|---|---|---|
| Is it possible to record audio downlink / play audio uplink during video call? | skylark_khur | Symbian Media (Graphics & Sounds) | 4 | 2008-09-24 08:12 |
| Problem when trying to record audio in MP4 format using Python (N80) | alb3530 | Python | 7 | 2007-02-07 19:12 |
| Half Duplex Audio Streaming | subhrajyotisaha | Symbian Media (Graphics & Sounds) | 0 | 2006-05-25 05:39 |
| HELP me , Using Audio Stream record AMR | tennist | Symbian Media (Graphics & Sounds) | 7 | 2006-04-13 11:12 |
| Can I record audio in .amr format in symbian 2.0 6620 phone | aficianado_001 | General Symbian C++ | 1 | 2005-12-08 09:32 |