如何使用纹理视图而不是surfaceview从摄像机直播视频?

时间:2017-01-31 13:23:46

标签: android rtmp live-streaming textureview android-textureview

我见过很多关于如何使用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) {

}

下一步做什么?

1 个答案:

答案 0 :(得分:0)

看看Texture View

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
    }
}