1

I'm trying to implement a video streaming between two devices with Android(API 9+) connected to the same WiFi network. First device operating as a small http server that records the video from the camera using MediaRecorder. The second device is trying to get the data using the method setDataSource from MediaPlayer class.

mediaPlayer.setDataSource("http://serverIP:port")

I know that first I need to send the correct header otherwise MediaPlayer will not be able to view the data. These are my questions:

  1. How should look correct header sent to the MediaPlayer?
  2. Is there a simpler solution for streaming video between android devices with API 9+ ?

I will be grateful for all the advice.

Edit:

Since my questions were too general I will try to be more specific. Based on this thread: Live-stream video from one android phone to another over WiFi I decided to create a small http server (using ServerSocket). When second device trying to connect via MediaPlayer I can send data to it from server using

socket.getOutputStream().write(buff, 0, readBytes);

But before sending the data, I must add the header to the response.

StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("HTTP/1.1 206 Partial Content\r\n");
stringBuilder.append("Content-Type: video/mp4\r\n");
stringBuilder.append("Accept-Ranges: bytes\r\n");
stringBuilder.append("Content-Length: XXXX\r\n\r\n");
socket.getOutputStream().write(stringBuilder.toString().getBytes());

Here is my problem. I do not know what information should be added to the header for the message to be understandable by the MediaPLayer. At the moment in the logs I see the following messages:

I/MediaHTTPConnection: response code = 206
V/MediaPlayer: message received msg=100, ext1=1, ext2=-2147483648
E/MediaPlayer: error (1, -2147483648)
Community
  • 1
  • 1
  • Welcome to Stack Overflow. Please read [How to Ask](http://stackoverflow.com/help/how-to-ask). A question with multiple questions is difficult to answer. Also please share what you have tried and/or researched. – zhon Aug 18 '16 at 19:36

1 Answers1

0

To send headers you have to put them in a Map as follows:

 Map<String, String> headers = new HashMap<>();
 headers.put("Header", "Value");

 media_player.setDataSource(
     getApplicationContext(),
     Uri.parse("http://url:port"),
        headers
 );
Kalizi
  • 457
  • 7
  • 21