2012-09-20 4 views
0

Nokia S40 시리즈 휴대폰에서 오디오 녹음 작업을하고 있습니다. 메시지를 녹음 할 수는 있지만 녹음 된 오디오 메시지를 재생할 수는 없습니다.Java ME에서 .amr 파일을위한 음성 또는 오디오 플레이어

기록 된 .amr 오디오 파일의 음성 플레이어를 코딩하는 방법을 알려줄 수있는 사람이 있습니까? 누구든지이 문제를 겪었습니까? 여기

답변

0

녹음 및 재생 사운드의 내 작업 예이다

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; 
     private Player player; 
     private byte[] recordedAudioArray = null; 
     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.OK, 0); 
      this.addCommand(record); 
      play = new Command("Play", Command.BACK, 0); 
      this.addCommand(play); 
      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(); 
            RecordControl rc = (RecordControl) player.getControl("RecordControl"); 
            ByteArrayOutputStream output = new ByteArrayOutputStream(); 
            rc.setRecordStream(output); 
            rc.startRecord(); 
            player.start(); 
            message.setText("Recording..."); 
            Thread.sleep(5000); 
            message.setText("Recording Done!"); 
            rc.commit(); 
            recordedAudioArray = output.toByteArray(); 
            player.close(); 
           } catch (Exception e) { 
            errormessage.setLabel("Error"); 
            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("Error"); 
         errormessage.setText(e.toString()); 
        } 
      } 
     } 
}