让一切的准备都完美演出,让所有的努力都美好落幕
分类: Android平台
2015-07-18 20:54:11
接下来看看官方文档中给出的创建RTSP服务器的步骤:
<service android:name="net.majorkernelpanic.streaming.rtsp.RtspServer"/>
把RtspServer这个服务在androidManifest文件中进行注册。在libstreaming库中,rtsp服务器是作为service组建实现的,这与spydroid的实现方式完全不一样。
Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit(); editor.putString(RtspServer.KEY_PORT, String.valueOf(1234)); editor.commit();
The port is indeed stored as a String in the preferences, there is a good reason to that. The EditTextPreference object saves its input as a String and cannot easily (one would need to override it) be configured to store it as an Integer.
可以改变rtsp服务器的端口,当然,这是非必需的。默认端口是8086。若想改变端口,必须通过sharedPreference完成。先获取一个指向本activity的sharedPreference的editor对象,再将指定的端口号put进去。至于为什么用String类型而不是用整形存储端口号,主要是考虑到EditTextPreference对象的保存类型是string。
3、Configure its behavior with the SessionBuilder:
SessionBuilder.getInstance() .setSurfaceHolder(mSurfaceView.getHolder()) .setContext(getApplicationContext()) .setAudioEncoder(SessionBuilder.AUDIO_AAC) .setVideoEncoder(SessionBuilder.VIDEO_H264);
4、Start and stop the server like this:
// Starts the RTSP server context.startService(new Intent(this,RtspServer.class)); // Stops the RTSP server context.stopService(new Intent(this,RtspServer.class));