首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2ME开发 >

j2me有关问题,有关怎么录音的有关问题

2011-11-29 
j2me问题,有关如何录音的问题?J2ME问题,有关如何录音的问题?第一个问题:我想编一个java小程序,录一段正在

j2me问题,有关如何录音的问题?
J2ME问题,有关如何录音的问题?    

第一个问题:

我想编一个java小程序,录一段正在播放的midi音乐。打算录5秒种时间.
我的代码如下:
try  
{
    Player   p   =   Manager.createPlayer(getClass().getResourceAsStream( "/air.mid "),   "audio/midi ");
  p.realize();
      //   Get   the   RecordControl,   set   the   record   stream,
        //   start   the   Player   and   record   for   5   seconds.
  p.prefetch();
        RecordControl   rc   =   (RecordControl)p.getControl( "RecordControl ");
        rc.setRecordLocation( "file:///audio2.wav ");
        rc.startRecord();
p.start();
Thread.currentThread().sleep(5000);
        rc.commit();
        p.close();
}  
catch   (IOException   ioe)  
{
}
catch   (MediaException   me)
{
}
catch   (InterruptedException   ie)
{
}
但是在运行过程中执行到rc.setRecordLocation( "file:///audio2.wav ")时,系统会报错,错误提示如下:
Uncaught   exception   java/lang/NullPointerException.


第二个问题:

但是如果我把程序改一下,如下:
  try  
  {
        Player   p   =   Manager.createPlayer( "capture://audio ");
        p.realize();
        //   Get   the   RecordControl,   set   the   record   stream,
        //   start   the   Player   and   record   for   5   seconds.
        RecordControl   rc   =   (RecordControl)p.getControl( "RecordControl ");
        rc.setRecordLocation( "file:///audio2.wav ");
        rc.startRecord();
        p.start();
        Thread.currentThread().sleep(5000);
        rc.commit();
        p.close();
  }  
  catch   (IOException   ioe)  
  {
  }  
  catch   (MediaException   me)  
  {
  }  
  catch   (InterruptedException   ie)
  {
  }
程序能够运行正常,但是打开audio2.wav文件,发现什么声音都没有,请教这是怎么回事?


[解决办法]
我觉得这个可能是跟文件没有创建有关系 ,你试试使用Stream来做
[解决办法]
录音处理错误
请参考MMAPI文档上的代码

Example
try {
// Create a Player that captures live audio.
Player p = Manager.createPlayer( "capture://audio ");
p.realize();
// Get the RecordControl, set the record stream,
// start the Player and record for 5 seconds.
RecordControl rc = (RecordControl)p.getControl( "RecordControl ");
ByteArrayOutputStream output = new ByteArrayOutputStream();
rc.setRecordStream(output);
rc.startRecord();
p.start();
Thread.currentThread().sleep(5000);
rc.commit();
p.close();
} catch (IOException ioe) {
} catch (MediaException me) {
} catch (InterruptedException ie) { }

------解决方案--------------------


按lz的意思,其实应该建立两个Player对象,一个放,一个录.
但似乎好像是不可以这样做的,没测试过,我觉得应该不支持一个放一个录啊.

saltedfish
[解决办法]
up

热点排行