1
votes

I’m building an android application. The app functionality is that it transfer audio file from one device to another via bluetooth.

I’m trying to play the file in chunks in media player. Means that reciever receive audio file in chunks,play this file and add next chunk into the existing file.

I’m sending chunks of bytes(audio file) to another device and adding followed chunks into it. Playing these chunks at receiver side.

But the is issue my app is crashing and getting this error:

Error: MediaPlayer prepare failed: status = 0x1

Here is my code:

This is my code where i am sending audiofile when devices are paired,

InputStream inStream = getResources().openRawResource(R.raw.comman);
                        byte[] music = inputStreamToByteArray(inStream);

                        // Invoke client thread to send
                         message = new Message();
                        message.obj = music;
                        MainApplication.clientThread.incomingHandler.sendMessage(message);

this is code where converting sending data into chunks:

 byte[] buffer = new byte[Constants.CHUNK_SIZE];
                Log.v(TAG, "Waiting for data.  Expecting " + progressData.remainingSize + " more bytes.");
                int bytesRead = inputStream.read(buffer);
                dataOutputStream.write(buffer, 0, bytesRead);
                progressData.remainingSize -= bytesRead;
                readBuf = buffer;

this is code where i am receiving chunks of bytes,

 File tempMp3 = File.createTempFile("kurchina", "mp3", getCacheDir());
        tempMp3.deleteOnExit();
        FileOutputStream fos = new FileOutputStream(tempMp3);
        fos.write(mp3SoundByteArray);  //mp3SoundByteArray is byte chunks
        fos.close();
        MediaPlayer mediaPlayer = new MediaPlayer();
        FileInputStream fis = new FileInputStream(tempMp3);
        FileDescriptor fileDescriptor = fis.getFD();
        mediaPlayer.reset();
        mediaPlayer.setDataSource(fileDescriptor);
        mediaPlayer.prepare();  // here my app is crashing
        mediaPlayer.start();
1
can we have error log!Nirav Ranpara
My error log is: java.io.IOException: Prepare failed.: status=0x1Shashank Gupta
Basically I am trying to create audio streaming app via bluetooth,could you please share some resource or tutorial to achieve this.I googled but have not found anything helpfull.Shashank Gupta

1 Answers

0
votes

Reason for this error

  1. File path is incorrect or Uri not Found!
  2. Missing permission
  3. Media file is incompatible format