RTSP stream in android with username and password

眉间皱痕 提交于 2019-12-04 19:51:08

Format is rtsp://[username[:password]@]ip_address[:rtsp_port]/server_U‌​RL[?param1=val1[&par‌​am2=val2]...[&paramN‌​=valN]]

Another way to send the username and password:

Uri source = Uri.parse("rtsp://iphere:554/cam/realmonitor");
Map<String, String> headers = new HashMap<String, String>();
headers.put("SERVER_KEY_TO_PARSE_USER_NAME", "admin");
headers.put("SERVER_KEY_TO_PARSE_PASSWORD", "pms7112");
mediaPlayer.setDataSource(context, source, headers)

Just a suggestion and optional try to call mediaplayer.prepareAsync() and not mediaplayer.prepare()

In order to access media presentations from RTSP servers that require authentication, the client MUST additionally be able to do the following: * recognize the 401 status code; * parse and include the WWW-Authenticate header; * implement Basic Authentication and Digest Authentication.

Reference Authentication-enabled

I just have found this project o github that uses vlc library to open rtsp streams.This solved my problem solved my problem

I would recommend using this library, its limited to 2 mins of playback but for my purposes that was not a problem.

https://github.com/VideoExpertsGroup/MediaPlayerSDK

I have tested multiple android libs and this one seems to work the best in android. Some other ones I have tested were choppy with playback or very delayed. There is also a test app so you can confirm it will work with your stream.

https://play.google.com/store/apps/details?id=org.rtspplr.app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!