javaandroidbluetoothfile-transfera2dp

How to stream music through multiple phones over bluetooth


I'm trying to connect some Android phones together to stream music.

The set up is like this,

Phone A is Connected to Phone B.

Phone B is also Connected to Phone C.

A <--> B <--> C

I want to stream music from A through B to C and hear it only on C.

I've looked into A2DP (here) but it appears to only support one device at a time.

Is there a way to stream using A2DP to B and then send it to C?

I'm trying come up with a solution that doesn't involve saving the file from A onto B and then streaming it using A2DP. The file could be big and the delay before playing should be short.

Are there ways to stream the file over and then send that stream from B to C using A2DP?

Are there other streaming options over Bluetooth? or Other Streaming Classes I could try and use once the data is in B?

Thanks


Solution

  • I found the AudioTrack class and I think this sort of solves my problem.

    I can send the music file as a byte[] using BluetoothSocket and BluetoothServerSocket classes across as many phones as I need to.

    Once I reach the end phone I create an AudioTrack object and write the bytes to it and play the music as a stream.

    The only limitation is that the file must be a .wav file and of a specific Bit Resolution, Sample Rate and Channel set up. Once I decided on which one I wanted to support I just converted the files I wanted to use with this website and streaming worked.

    Note: This solution is very noisy. I'm looking into how to I can fix that.