0

How to get bytes from audio file in blackberry. I used file picker and uploaded the audio. I tried this -

FileConnection fc= (FileConnection)Connector.open(sel);
InputStream is=fc.openInputStream();
ReimgData = IOUtilities.streamToBytes(is);

i have to use any encoding methods ?.

On image encoding, we use the following code for encoding

                    EncodedImage encode_image =EncodedImage.createEncodedImage(ReimgData, 0, (int)fc.fileSize());
                    JPEGEncodedImage encoder=JPEGEncodedImage.encode(encode_image.getBitmap(),50);
                    byte[] array=encoder.getData();
                    // Decodes the image represented by this EncodedImage and returns a Bitmap
                    int length=array.length;
                    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(length);
                    Base64OutputStream base64OutputStream = new Base64OutputStream( byteArrayOutputStream );
                     try{
                                     base64OutputStream.write( array, 0, length );
                                     base64OutputStream.flush();
                                     base64OutputStream.close();
                                 }
                                    catch (IOException ioe){
                                    //Dialog.alert("Error in encodeBase64() : "+ioe.toString());
                                    System.out.println("Error in encodeBase64() : "+ioe.toString());

                                 }

                                 //----Decoding image

                                 try
                                 {
                                    System.out.print(byteArrayOutputStream.toString());
                                      //Dialog.alert(byteArrayOutputStream.toString()+"");
                                      data = Base64InputStream.decode(byteArrayOutputStream.toString());
4

1 回答 1

0

您可以从音频文件(或任何文件)中读取字节,如下所示:

FileConnection file = (FileConnection)Connector.open("yourfile.mp3");
InputStream audioStream = file.openInputStream();

byte[] audioData = IOUtilities.streamToBytes(audioStream);
audioStream.close();
file.close();
于 2012-04-19T09:35:42.710 回答