0

我被困在这个小复杂的情况下。我正在编写 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>()帮助我。

4

2 回答 2

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--;
于 2013-10-30T09:17:51.693 回答
0

这是答案。

                      while (TotalBuffer !=0){
                      buffer= new byte[AClipTextFileHandler.BufferSize.get(j)];
                      input.read(buffer);
                      j++;
                      TotalBuffer--;

其中 j 是从文本文件中获取的字节数组的大小。TotalBuffer 是要创建的字节数组的数量,它再次取自文本文件。

于 2013-10-30T12:03:00.270 回答