Android: send Audio splitted in chunks, rejoin at destination and playback -


i coding android app (try to) send audio app.

component: audiorecord recording audiotrack playback

here comes problem:

while on long press, i'm recording data in short[] variable (i convert in byte[] short after)

private void writebuffer() {     sdata = new short[1024];     while (isrecording) {         recorder.read(sdata, 0, 1024);     } } 

i want send chunks of sdata every 1 second , play on other app array of byte second second

t.schedule(new timertask() {                         @override                         public void run() {                             runonuithread(new runnable() {                                 @override                                 public void run() {                                     audiomessage = new audiomessage(getsdata(), idorigin, iddestination);                                     mservice.sendaudio(am);                                 }                             });                          }                     }, 1000); 

audiomessage wrapper class timestamp , byte data[] variable. getsdata() getter return sdata recorded , clean variable.

for playback instead receive message broadcastreceiver

queue<byte[]> audiobuffer = new linkedlist<>(); @override protected void receivedmessage(socketframe data) {     super.receivedmessage(data);     if (data.gettype() == socketenum.audio) {         audiobuffer.offer(data.getaudiomessage().getmessage());         playfrombuffer();     } 

i put every chunk in queue , try play them iterator

void playfrombuffer(){      if (!playing) {         playing = true;         iterator<byte[]> iter = audiobuffer.iterator();         while (iter.hasnext()) {             byte[] chunk = iter.next();             ar.play(chunk);             iter.remove();         }         playing = false;     } } 

and play() use audiotrack

public void play(byte data[]) {     player.play();     player.write(data, 0, data.length);     player.stop(); } 

is correct? or @ least logical? way not work.

i cannot use send methods. can send objects data wrapped inside , broadcastreceiver alert ui in other app message received.

i can send data @ once cannot play audio till it's received , don't need this.

can split pcm audio arbitrary , read bytes audio? suggestions?

ty all

d


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -