Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android TextureView set background color and show video later

Tags:

android

Thanks everyone.
I have a TextureView to show a video using MediaPlayer. Before the video is downloaded, I prefer to show a background color. How to do that ?

My code below is not working :(
Screen is not updated after play is called

public void play(String filename) {
    try {
        mPlayer.setDataSource(filename);
        mPlayer.setSurface(new Surface(getSurfaceTexture()));
        mPlayer.prepare();
        mPlayer.setLooping(true);
        mPlayer.start();
    } catch (IOException e) {
        Log.e("@", "fail to play video");
    }
}

public void setPlaceholderColor(int color) {
    Canvas canvas = lockCanvas();
    canvas.drawColor(color);
    unlockCanvasAndPost(canvas);
}
like image 301
Darcy Avatar asked Feb 15 '14 06:02

Darcy


1 Answers

Put your TextureView on a layout alone. And set the layouts background color the color you want. Also set TextureView opacity to null.

like image 176
gvlachakis Avatar answered Nov 15 '22 01:11

gvlachakis