RTSP stream in android with username and password

我的未来我决定 提交于 2019-12-06 14:21:28

问题



My task is to create an android application in android to check some IP cameras of the city. Using the existing RTSP url which is rtsp://admin:pms7112@xxx.xx.xx.xxx:554/cam/realmonitor?channel=1&subtype=0 I can get the stream in VLC player but no luck in android. I have tried videoview native player and media player.
Almost every solution gave me

MediaPlayer: setDataSource IOException happend : java.io.FileNotFoundException: No content provider: rtsp://...

Should this problem happen because the username and password is in the string? how could you add the username and password as query string?

EDIT
Mediaplayer version
MediaPlayer mediaPlayer = new MediaPlayer();

    try
    {
        mediaPlayer.setDataSource("rtsp://admin:pms7112@iphere:554/cam/realmonitor?channel=1&subtype=0");
        mediaPlayer.prepare();
        mediaPlayer.start();
    }
    catch (IOException ex)
    {
        ex.printStackTrace();
    } 


Update:
So...it seems that this is the only way I could use the url...I cannot authenticate the user other way. The conpany which owns the camera and setted up for the city do not let us to use other formats. They said, vlc browser addon plays just fine and they will not change anything... So is there any library that implements the rtsp stream with authentication. I heard about a handshake that is made between the client and the server


回答1:


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




回答2:


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




回答3:


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



来源:https://stackoverflow.com/questions/42573257/rtsp-stream-in-android-with-username-and-password

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