我正在尝试录制音频文件并播放它,但我收到了错误:Locator does not reference a valid media file
。我错过了什么?
这是我保存音频文件的代码:
//Stop recording, capture data from the OutputStream,
//close the OutputStream and player.
_rcontrol.commit();
_data = _output.toByteArray();
_output.close();
_player.close();
isRecording = 0;
try {
FileConnection fc = (FileConnection)Connector.open("file:///store/home/user/Audio.mp3");
// If no exception is thrown, then the URI is valid, but the file may or may not exist.
if (!fc.exists()) {
fc.create(); // create the file if it doesn't exist
}
OutputStream outStream = fc.openOutputStream();
outStream.write(_data);
outStream.close();
fc.close();
System.out.println("audio size: "+_data.length);
我可以在日志中看到我的音频文件有一定的长度(录制3-4秒后约为5000) 这是我的代码,我正在尝试播放它:
FileConnection fc = (FileConnection)Connector.open("file:///store/home/user/Audio.mp3");
// If no exception is thrown, then the URI is valid, but the file may or may not exist.
if (fc.exists()) {
_player = Manager.createPlayer("file:///store/home/user/Audio.mp3");
_player.realize();
_player.prefetch();
if (_player.getMediaTime() == _player.TIME_UNKNOWN) {
System.out.println("zero audio doration");
}
else {
System.out.println("audio doration: "+_player.getMediaTime());
}
_player.start();
}
fc.close();