audio stream with B2 and andorid studio?

0

I am trying to establish a data transmission (send a sound) to my phone through a module B2 HC-05/06, and I would like to know if it is possible for my phone to play the audio stream, if so, it would be great help if you gave me some idea of how to do it, a flow chart or a page that serves as a guide.

    
asked by Frankarlo Jurado 09.09.2017 в 18:14
source

1 answer

0

Here I leave this example working, how to play stream via android studio

import java.io.IOException;

import android.media.MediaPlayer;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {

@Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);

 try {
 MediaPlayer mediaPlayer = new MediaPlayer();
 mediaPlayer.setDataSource("http://10.0.2.2:8000/;stream.mp3");
 mediaPlayer.prepare();
 mediaPlayer.start();
 } catch (IllegalArgumentException e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
 } catch (SecurityException e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
 } catch (IllegalStateException e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
 } catch (IOException e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
 }

}

@Override
 public boolean onCreateOptionsMenu(Menu menu) {
 // Inflate the menu; this adds items to the action bar if it is present.
 getMenuInflater().inflate(R.menu.main, menu);
 return true;
 }

}

What you should add is:

import android.media.MediaPlayer;

And the following lines:

MediaPlayer mediaPlayer = new MediaPlayer();
 mediaPlayer.setDataSource("http://10.0.2.2:8000/;stream.mp3");
 mediaPlayer.prepare();
 mediaPlayer.start();

I wait for my little dove: D

    
answered by 09.09.2017 в 18:42