我见过很多关于如何使用surfaceview将视频从Android摄像头直播到rtmp服务器的示例。一个在这里:https://github.com/begeekmyfriend/yasea
但是可以使用textureview将视频从相机流式传输到rtmp吗?如果是的话,我们怎么样?
Textureview mTextureView;
// inside oncreate
mTextureView = (TextureView) findViewById(R.id.texture_view);
mTextureView.setSurfaceTextureListener(AircraftControlActivity.this);
// Outside OnCreate
@Override
public void onSurfaceTextureAvailable(final SurfaceTexture surface, final int width, final int height) {
}
@Override
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
}
@Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
}
@Override
public void onSurfaceTextureUpdated(final SurfaceTexture surface) {
}
下一步做什么?
答案 0 :(得分:0)
public class MainActivity extends AppCompatActivity implements TextureView.SurfaceTextureListener
{
Camera camera;
TextureView textureView;
ImageButton button ; //ignore this one
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textureView = (TextureView) findViewById(R.id.textureView);
button = (ImageButton)findViewById(R.id.imageButton);
textureView.setSurfaceTextureListener(this);
}
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height)
{
camera = Camera.open();
try
{
camera.setPreviewTexture(surface);
camera.startPreview();
}
catch (IOException ioe)
{
// Something bad happened
}
}
@Override
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height)
{
// Ignored, Camera does all the work for us
}
@Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface)
{
camera.stopPreview();
camera.release();
return true;
}
@Override
public void onSurfaceTextureUpdated(SurfaceTexture surface)
{
// Invoked every time there's a new Camera preview frame
}
}