无法在 Android 中实施 RTSP 服务器

Unable to implement RTSP server in Android

我正在尝试在 Android 中实现一个轻量级 RTSP 服务器,以将我的相机源实时流式传输到 VLC 媒体播放器。为此,我在服务器端使用 libstreaming library. I successfully imported the library in Android Studio and managed to compile and run the skeleton code。不幸的是,该程序没有按预期运行。相机预览加载失败,我无法在 VLC 媒体播放器中读取 MRL。有没有人遇到过这个问题?任何帮助,将不胜感激!提前致谢。到目前为止,这是我尝试过的:

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

    }

}

我正在尝试访问 MRL:rtsp://192.168.2.3:1234/

您尝试的代码很好。 URL需要有特定的格式,

URL 在 VLC 播放器中应该是 rtsp://phone_local_ip:1234?h264=200-20-320-240

200 = 缓冲器 | 20 = 每秒帧数 | 320 = 宽度 | 240 = 高度