Vinit Shandilya
Vinit Shandilya

Reputation: 1643

Unable to implement RTSP server in Android

I'm trying to implement a lightweight RTSP server in Android to live-stream my camera feed to VLC media player. For this, I'm using libstreaming library. I successfully imported the library in Android Studio and managed to compile and run the skeleton code for server side. Unfortunately, the program is not working as expected. The camera preview fails to load and I'm unable to read the MRL in VLC media player. Has anyone faced this issue before? Any help would be appreciated! Thanks in advance. Here is what I've tried so far:

    public class MainActivity extends Activity {

    private final static String TAG = "MainActivity";

    private SurfaceView mSurfaceView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        setContentView(R.layout.activity_main);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

        mSurfaceView = (SurfaceView) findViewById(R.id.surface);

        // 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));

    }

}

I'm trying to access the MRL: rtsp://192.168.2.3:1234/

Upvotes: 2

Views: 1372

Answers (1)

Umair
Umair

Reputation: 1236

The code you are trying is good. The URL needs to have specific format,

URL in VLC player should be rtsp://phone_local_ip:1234?h264=200-20-320-240

200 = buf | 20 = fps | 320 = width | 240 = height

Upvotes: 3

Related Questions