5

我已经看到了很多关于如何使用 Surfaceview 将视频从 android 相机实时流式传输到 rtmp 服务器的示例。一个在这里:https ://github.com/begeekmyfriend/yasea

但是是否可以使用纹理视图将视频从相机流式传输到 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) {

}

接下来做什么?

4

1 回答 1

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
    }
}
于 2018-07-28T22:01:34.343 回答