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
Format is rtsp://[username[:password]@]ip_address[:rtsp_port]/server_URL[?param1=val1[¶m2=val2]...[¶mN=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
来源:https://stackoverflow.com/questions/42573257/rtsp-stream-in-android-with-username-and-password