我陷入了这种复杂的局面。我正在编写android应用程序的一部分,我正在将Mp3文件读入多个字节数组。问题是这个字节数组的数量将由USB的文本文件以及每个字节数组的大小决定。 请建议我一个出路。
以下是我正在阅读Mp3文件的代码
cxt = ControlUnit.getAppContext();
try {
File file = new File("/mnt/media/USBDISK1/IFrame_00.bin");
input = new BufferedInputStream(new FileInputStream(file));
//input = cxt.getAssets().open("Maid with the Flaxen Hair.mp3");
Log.i("TvPlayerFunctionalTestApp", "mp3 file Read from Assests");
} catch (IOException e) {
// TODO Auto-generated catch block
Log.i("TvPlayerFunctionalTestApp", "Error in Opening mp3 File");
e.printStackTrace();
}
try {
size = input.available();
Log.i("TvPlayerFunctionalTestApp", "Size of Bin File: "+size);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
buffer = new byte[AClipTextFileHandler.BufferSize.get(0)];
input.read(buffer);
// input.read(buffer, offset, length);
Log.i("TvPlayerFunctionalTestApp", "buffer: "+ Arrays.toString(buffer));
buffer1 = new byte[AClipTextFileHandler.BufferSize.get(1)];
input.read(buffer1);
Log.i("TvPlayerFunctionalTestApp", "buffer: "+ Arrays.toString(buffer1));
StringBuffer stringBuff = new StringBuffer();
for (byte b:buffer)
{
stringBuff.append(String.format("%x", b));
}
Log.i("TvPlayerFunctionalTestApp","buffer: "+stringBuff) ;
for (byte b:buffer1)
{
stringBuff.append(String.format("%x", b));
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.i("TvPlayerFunctionalTestApp", "Error in Read");
}
try {
input.close();
Log.i("TvPlayerFunctionalTestApp", "File closed");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
我无法理解List<Byte> arrays = new ArrayList<Byte>()
如何帮助我。
答案 0 :(得分:0)
以下尝试怎么样? 总缓冲区将从我正在阅读的文本文件中获取。
int TotalBuffer = AClipTextFileHandler.BufferID.get(0);
while (TotalBuffer !=0){
bufferData[i]= new byte[AClipTextFileHandler.BufferSize.get(j)];
input.read(bufferData[i]);
i++;
j++;
TotalBuffer--;
答案 1 :(得分:0)
这是答案。
while (TotalBuffer !=0){
buffer= new byte[AClipTextFileHandler.BufferSize.get(j)];
input.read(buffer);
j++;
TotalBuffer--;
其中j是从文本文件中获取的字节数组的大小。 TotalBuffer是要创建的字节数组的数量,它再次从文本文件中获取。