5

I have seen many examples on how to live stream video from android camera to rtmp server using surfaceview. One is here : https://github.com/begeekmyfriend/yasea

But is it possible to stream the video from camera to rtmp using a textureview? If it is, how can we?

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) {

}

What to do next?

cakan
  • 2,099
  • 5
  • 32
  • 42

1 Answers1

0

Take a look at 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
    }
}
CertainPerformance
  • 356,069
  • 52
  • 309
  • 320
sass
  • 73
  • 1
  • 2
  • 8