Android Live Streaming using MJPG on HTTP or RTSP protocol

Viewed 459

I purchased ESP32 camera and installed code on ESP32 camera using Arduino IDE. I am able to see the feed on chrome and VLC. I am writing an android app which used Android MediaPlayer and Surface View to view the live streaming video. But in the android app I am not able to view the stream.

In the ESP32 Camera, I tried with both HTTP and RTSP protocol. In both the cases, facing the following error in media player

12-01 09:57:58.446 20282 20282 E Cam_VideoStreamPreview: Mediaplayer info :: what = 701, extra = 0
12-01 09:57:59.657 20282 20297 E MediaPlayerNative: error (1, -2147483648)
12-01 09:57:59.657 20282 20282 E MediaPlayer: Error (1,-2147483648)

Media Player logic in code

//private const val STREAM_URI = "http://192.168.1.11/stream"
//private const val STREAM_URI = "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"
//private const val STREAM_URI = "http://techslides.com/demos/sample-videos/small.mp4"
//private const val STREAM_URI = ""
//private const val STREAM_URI = "https://www.learningcontainer.com/wp-content/uploads/2020/05/sample-mp4-file.mp4"
//private const val STREAM_URI = "http://192.168.1.8:8080/Downloads/Sintel.mp4"
private const val STREAM_URI = "rtsp://192.168.1.11:8554/mjpeg/1"

val mediaPlayer = MediaPlayer().apply {
            setAudioAttributes(
                    AudioAttributes.Builder()
                            .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
                            .setUsage(AudioAttributes.USAGE_MEDIA)
                            .build()
            )
            setDataSource(STREAM_URI)
        }

I then do prepare and then in that callback I will call the start method from mediaplayer.

Content Type Http Response

In the ESP32 camera, we use HTTP Live Streaming protocol. Output format will be in MJPG format. Initial header response will have Content-Type as multipart/x-mixed-replace;boundary=123456789000000000000987654321. All the chunked response will have Content-Type as image/jpeg

*   Trying 192.168.1.11...
* TCP_NODELAY set
* Connected to 192.168.1.11 (192.168.1.11) port 80 (#0)
> GET /stream HTTP/1.1
> Host: 192.168.1.11
> User-Agent: curl/7.54.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Content-Type: multipart/x-mixed-replace;boundary=123456789000000000000987654321
< Transfer-Encoding: chunked
< Access-Control-Allow-Origin: *
<
HTTP/1.1 200 OK
Content-Type: multipart/x-mixed-replace;boundary=123456789000000000000987654321
Transfer-Encoding: chunked
Access-Control-Allow-Origin: *

Content-Type: image/jpeg
Content-Length: 6503

I have the following doubts

  1. I checked the supported media requirements from android (https://developer.android.com/guide/topics/media/media-formats#network ). They support HLS and RTSP protocol. Whether the Content-Type would be a problem here?
  2. Whether there are any alternatives to android media player. Can I read the chunks myself and display in android? Whether such thing is possible in android?
0 Answers
Related