Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I'm trying to use VLC as a RTSP client. The RTSP server is based on the
libstreaming
library. I'm using the code provided by the
1rst example
:
// Sets the port of the RTSP server to 1234
Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit();
editor.putString(RtspServer.KEY_PORT, String.valueOf(1234));
editor.commit();
// Configures the SessionBuilder
SessionBuilder.getInstance()
.setSurfaceView(mSurfaceView)
.setPreviewOrientation(90)
.setContext(getApplicationContext())
.setAudioEncoder(SessionBuilder.AUDIO_NONE)
.setVideoEncoder(SessionBuilder.VIDEO_H264);
// Starts the RTSP server
this.startService(new Intent(this,RtspServer.class));
The android app starts; I try to access the stream using VLC (open a stream
) and this URL:
rtsp://192.168.43.250:1234
The device is connected to the same network (I can ping it), but nothing happens in the android App and VLC displays a "connection failed" window.
Any idea where the problem is? Maybe a bad URL, but I can't found any detailled example of this situation.
It throws null pointer, check the logcat.
you have to provide the url as rtsp://ip:1234?h264=200-20-320-240
200 - buf
20 - fps
320 - resolution w
240 - resolution h
–
Use this code for you MainActivity:
public class MainActivity extends AppCompatActivity implements SurfaceHolder.Callback, RtspServer.CallbackListener, Session.Callback{
private final static String TAG = "MainActivity";
private SurfaceView mSurfaceView;
private Session mSession;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
mSurfaceView = (SurfaceView) findViewById(R.id.surface);
// Sets the port of the RTSP server to 1234
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit();
editor.putString( RtspServer.KEY_PORT, String.valueOf(1234));
editor.commit();
// Configures the SessionBuilder
mSession = SessionBuilder.getInstance()
.setCallback(this)
.setSurfaceView((net.majorkernelpanic.streaming.gl.SurfaceView) mSurfaceView)
.setPreviewOrientation(90)
.setContext(getApplicationContext())
.setAudioEncoder(SessionBuilder.AUDIO_AAC)
.setAudioQuality(new AudioQuality(8000, 16000))
.setVideoEncoder(SessionBuilder.VIDEO_H264)
//.setVideoQuality(new VideoQuality(320,240,20,500000))
.build();
mSurfaceView.getHolder().addCallback(this);
((net.majorkernelpanic.streaming.gl.SurfaceView) mSurfaceView).setAspectRatioMode(net.majorkernelpanic.streaming.gl.SurfaceView.ASPECT_RATIO_PREVIEW);
String ip, port, path;
// Starts the RTSP server
this.startService(new Intent(this,RtspServer.class));
Log.d("test", "1");
mSession.startPreview(); //camera preview on phone surface
mSession.start();
@Override
public void onResume()
super.onResume();
mSession.stopPreview();
@Override
public void onDestroy()
super.onDestroy();
mSession.release();
mSurfaceView.getHolder().removeCallback(this);
//region ----------------------------------implement methods required
@Override
public void onError(RtspServer server, Exception e, int error) {
Log.e("Server", e.toString());
@Override
public void onMessage(RtspServer server, int message) {
Log.e("Server", "unkown message");
@Override
public void onBitrateUpdate(long bitrate) {
@Override
public void onSessionError(int reason, int streamType, Exception e) {
@Override
public void onPreviewStarted() {
@Override
public void onSessionConfigured() {
@Override
public void onSessionStarted() {
@Override
public void onSessionStopped() {
@Override
public void surfaceCreated(SurfaceHolder holder) {
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
//endregion
using VLC player open the open network stream and type
rtsp://the ip of android device:1234 <--this port is hard coded so don't change
))) the first example is a server (for the author of the library, the server is someone who accepts the stream and does not give)
you need to use 2 or 3 example ...
2 example is good because you only need a VLK player ...
find out your Ip (cmd-> ipconfig) (it's important to understand that the device must have an external ip address or is in the same network)
Specify the received ip address of the PC in mEditText (mSession.setDestination ();)
After launching the application, press the start button. The studio in the logs will return the contents to create the sdp format file (TAG, mSession.getSessionDescription ());
create a falix for example 1.sdp edit it by specifying the contents of getSessionDescription (remove extra spaces)
huge minutes then that we need to specify the ip of the one we want to send the stream to ...
now the main thing! in any of the examples it does not turn out to simply enter rtsp: //192.168.43.250: 1234 and get the video !!! - 0)))))))
In the Session class, you'll find mOrigin = "127.0.0.1"; ok SessionBuilder .... .setOrigin ("192.xxx.xxx.xx")
Further your logic may suggest that you only need to find the port and maybe you will find SessionBuilder Session build () video.setDestinationPorts (5006);
but this is not the port)))
in this library there is no rtsp server implementation (I'm writing a server since it means that we want to raise the server for ip cam on the device)
you can find the hint in the RtspClient class (pay attention to the author of the library, this is the one who gives it) and there the author writes to us
* RFC 2326.
* A basic and asynchronous RTSP client.
RTSP client compatible with Wowza.
* It implements Digest Access Authentication according to RFC 2069.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.