gpt4 book ai didi

android - 如何使用纹理 View 而不是表面 View 从相机直播视频?

转载 作者:太空狗 更新时间:2023-10-29 14:44:37 24 4
gpt4 key购买 nike

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

}

接下来要做什么?

最佳答案

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

关于android - 如何使用纹理 View 而不是表面 View 从相机直播视频?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41958741/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com