I have a TextureView that displays a bitmap(placeholder image) and when the user loads a video the textureView should show the video.
I managed to get video playback in the texture view and showing a bitmap in a textureview, but when done in sequence i just get a black screen.
In my onSurfaceTextureAvailable method i draw a bitmap on the surface view as followed:
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.ic_add_clip);
Canvas canvas = lockCanvas();
canvas.drawBitmap(bm, (width/2)-(bm.getWidth()/2), (height/2)-(bm.getHeight()/2), null);
unlockCanvasAndPost(canvas);
}
When the user selects a video from its gallery i load the Uri in the Media player and set the surface to the mediaplayer. But the bitmap is still shown. i tried to remove the bitmap by clearing the canvas, and it does remove the bitmap but then the texture view is just black and won't show the video as well.
public void setMediaPlayer(MediaPlayer mediaPlayer) {
// Canvas canvas = lockCanvas();
// canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
// unlockCanvasAndPost(canvas);
Surface s = new Surface(getSurfaceTexture());
mMediaPlayer = mediaPlayer;
mMediaPlayer.setSurface(s);
mMediaPlayer.setOnPreparedListener(this);
}
Something tells me that the surface view i'm using to display the video is behind the bitmap that i draw in the on TextureAvailble. And when i try to clear the canvas i also clear the surface that the mediaplayer wants to use. Any solutions?