transfer music from phone to arduino

how can I transfer music from phone to arduino by bluetooth? the music format is .mp3. Can I send .mp3 like char to arduino by bluetooth? How can I store the data which receive from android? I can't read the music format. by the way,I transfer char or string from phone to arduino by bluetooth. Bluetooth->HC-06,Arduino->Mega2560,sd card module

how can I transfer music from phone to arduino by bluetooth?

For what purpose?

the music format is .mp3.

No, it isn't. It's a stream of bytes that some application interprets as being in the mp3 format, so the application can make use of the data. The Arduino can not do that. It would have no idea what to do with the data.

Can I send .mp3 like char to arduino by bluetooth?

Yes, because char and byte are the same size. The data will never be interpreted as characters, so using the wrong type won't matter. It would, of course, be better to use the right type, so that you are not tempted to try to print the data.

How can I store the data which receive from android?

That depends entirely on where you intend to store it. The hard drive on the Arduino is pretty small.

I can't read the music format.

Then the project is a non-starter. Of course, if you meant that you can't make sense of the data when it is printed out, then the question is why you thought you should be able to.

PaulS: For what purpose?

I want to make a headset,so I prefer using bluetooth than connecting to PC to store music.

PaulS: the music format is .mp3.

Sorry,I forget it.I have a music shield. http://www.seeedstudio.com/wiki/Music_Shield_V2.0 It can play music.

PaulS: Can I send .mp3 like char to arduino by bluetooth?

I can send text to arduino,so I having a method sending .mp3 like char to arduino by bluetooth. but I can't read the mp3 format.

PaulS: I can't read the music format.

If I can read it,sending music like text. but I don't understand the format. How can I send music by bluetooth?

but I can't read the mp3 format.

From a reading point of view, it is a file containing some bytes. The extension, or the meaning associated with the bytes, is completely irrelevant.

but I don't understand the format.

You don't need to understand the format. The Arduino won't be able to, either. The best you can do is stream the contents of the file to the Arduino, and have it read the data and store it on the SD card. Once the whole file has been streamed over, then the mp3 shield can play the file from the SD card.

AKAI: The best you can do is stream the contents of the file to the Arduino, and have it read the data and store it on the SD card. Once the whole file has been streamed over, then the mp3 shield can play the file from the SD card.

Sorry,I don't know 'stream' meaning.Can you give some example or explain clearly? Thank you. I have used Arduino on April.

Sorry,I don't know 'stream' meaning.

It means that you read a byte (or collection of bytes) from the file, and send the byte (or collection of bytes) out of the phone in the order read.

I receive data from Android with bluetooth. if (BTSerial.available() > 0) {

data = BTSerial.read(); Serial.println(data); }

how can I read a byte (or collection of bytes) from the file? stream.available() ?

how can I read a byte (or collection of bytes) from the file?

The file does not exist on the Arduino. Therefore, you can't read a byte, or collection of bytes, from the file ON THE ARDUINO.

You have to read the byte (or collection of bytes) from the file ON THE PHONE, and send them to the Arduino.

I send file from Android.
String path = Environment.getExternalStorageDirectory().getPath();
File file = new File(path + “/”+ “abab.txt”);
StringBuilder sb = new StringBuilder();
try {
FileInputStream fin = new FileInputStream(file);
byte data = new byte[fin.available()];
while (fin.read(data) != -1) {
sb.append(new String(data));
Bluetooth.connectedThread.write(new String(data));
}
fin.close();
Log.i(“TAG OVER”,“OK OK OK OK OK OK OK OK OK”);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Log.d(“TAG”, "Read from SDCARD: " + sb.toString());
text.setText(sb.toString());

and write function

public void write(String income) {

try {
mmOutStream.write(income.getBytes());
for(int i=0;i<income.getBytes().length;i++)
Log.v(“outStream”+Integer.toString(i),Character.toString((char)
(Integer.parseInt(Byte.toString(income.getBytes())))));

  • try {*

  • Thread.sleep(20);*

  • } catch (InterruptedException e) {*

  • // TODO Auto-generated catch block*

  • e.printStackTrace();*

  • }*

  • } catch (IOException e) { }*

  • }*
    is right?
    Arduino side receive data
    if (BTSerial.available() > 0)

  • {*

  • data = BTSerial.read();*

  • Serial.println(data);*

  • }*

StringBuilder sb = new StringBuilder();

You are NOT going to be sending a string.

is right?

No.

Your indenting sucks. Your code is NOT posted correctly.

I do another way. but I can't success.

String path = Environment.getExternalStorageDirectory().getPath(); File file = new File(path + "/" + "abab.txt");

try { FileInputStream fin = new FileInputStream(file); byte[] data = new byte[1024]; int length = -1; while ((length = fin.read(data)) != -1) { Bluetooth.connectedThread.write(new String(data)); } fin.close(); Log.i("TAG OVER", "OK OK OK OK OK OK OK OK OK"); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } What function can collect byte?

   Bluetooth.connectedThread.write(new String(data));

Why the hell do you insist on sending binary data as Strings?

AKAI: Bluetooth.connectedThread.write("send message");

this is my send message method,bacause I don't know how to send. how can I sending the data?

how can I sending the data?

Just send the data. Do not wrap it in a String!

I should write a new method?
The write function’s parameter is string.

public void write(String income) {

try {
mmOutStream.write(income.getBytes());
for(int i=0;i<income.getBytes().length;i++)
Log.v(“outStream”+Integer.toString(i),Character.toString((char)
(Integer.parseInt(Byte.toString(income.getBytes())))));

  • try {*
  • Thread.sleep(20);*
  • } catch (InterruptedException e) {*
  • // TODO Auto-generated catch block*
  • e.printStackTrace();*
  • }*
  • } catch (IOException e) { }*
  • }*