我正在尝试为Google Glass构建一个可以流式传输到服务器并让客户端通过Web浏览器查看流的应用程序.到目前为止,我似乎需要通过RTSP到Wowza等媒体服务器这样做,然后有一个托管一些视频播放器的Web服务器来查看RTMP流,但我没有太多运气.
使用libstreaming(https://github.com/fyhertz/libstreaming)我永远无法查看流.
我也有兴趣使用WebRTC做一些事情,这样我就可以制作类似于Hangouts的解决方案,但我不确定是否有任何支持这个的库.
任何帮助表示赞赏.
解决方法:
从1月份开始,libsreaming已被修复为Glass上的工作.它的RTSP视频可以在VLC播放器或插件中轻松查看.下面的代码不包括自动生成的存根.
public class MainActivity extends Activity implements SurfaceHolder.Callback, Session.Callback {
private int mRtspPort = -1;
private ServiceConnection mRtspServerConnection = new ServiceConnection() {
private static final int RTSP_PORT = 1234;
@Override
public void onServiceConnected(ComponentName className, IBinder binder) {
RtspServer s = ((RtspServer.LocalBinder) binder).getService();
s.setPort(RTSP_PORT);
mRtspPort = s.getPort();
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestwindowFeature(Window.FEATURE_NO_TITLE);
getwindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getwindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.activity_main);
// Configures the SessionBuilder
SessionBuilder.getInstance()
.setSurfaceView((SurfaceView) findViewById(R.id.surface))
.setCallback(this)
.setPreviewOrientation(90)
.setContext(getApplicationContext())
.setAudioEncoder(SessionBuilder.AUdio_NONE)
.setVideoEncoder(SessionBuilder.VIDEO_H264)
.setVideoQuality(new VideoQuality(320, 240, 20, 500000));
// Starts the RTSP server
bindService(new Intent(this, RtspServer.class), mRtspServerConnection, Context.BIND_AUTO_CREATE);
}
@Override
public void onResume() {
super.onResume();
mResumed = true;
displayConnectString();
SessionBuilder.getInstance().getSurfaceView().setAspectRatioMode(SurfaceView.ASPECT_RATIO_PREVIEW);
SessionBuilder.getInstance().getSurfaceView().getHolder().addCallback(this);
}
private void displayConnectString() {
WifiManager wifiMgr = (WifiManager) getSystemService(WIFI_SERVICE);
WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
int ip = wifiInfo.getIpAddress();
String ipAddress = Formatter.formatIpAddress(ip);
((TextView) findViewById(R.id.connectInfo)).setText("rtsp://" + ipAddress + ":" + mRtspPort);
}
@Override
public void onDestroy() {
super.onDestroy();
unbindService(mRtspServerConnection);
}
@Override
public void onSessionStarted() {
((TextView) findViewById(R.id.connectInfo)).setText("");
}
@Override
public void onSessionStopped() {
displayConnectString();
}
}