1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.google.android.exoplayer2.video; 17 18 import android.content.Context; 19 import android.opengl.GLSurfaceView; 20 import android.util.AttributeSet; 21 import androidx.annotation.Nullable; 22 23 /** 24 * GLSurfaceView for rendering video output. To render video in this view, call {@link 25 * #getVideoDecoderOutputBufferRenderer()} to get a {@link VideoDecoderOutputBufferRenderer} that 26 * will render video decoder output buffers in this view. 27 * 28 * <p>This view is intended for use only with extension renderers. For other use cases a {@link 29 * android.view.SurfaceView} or {@link android.view.TextureView} should be used instead. 30 */ 31 public class VideoDecoderGLSurfaceView extends GLSurfaceView { 32 33 private final VideoDecoderRenderer renderer; 34 35 /** @param context A {@link Context}. */ VideoDecoderGLSurfaceView(Context context)36 public VideoDecoderGLSurfaceView(Context context) { 37 this(context, /* attrs= */ null); 38 } 39 40 /** 41 * @param context A {@link Context}. 42 * @param attrs Custom attributes. 43 */ VideoDecoderGLSurfaceView(Context context, @Nullable AttributeSet attrs)44 public VideoDecoderGLSurfaceView(Context context, @Nullable AttributeSet attrs) { 45 super(context, attrs); 46 renderer = new VideoDecoderRenderer(this); 47 setPreserveEGLContextOnPause(true); 48 setEGLContextClientVersion(2); 49 setRenderer(renderer); 50 setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); 51 } 52 53 /** Returns the {@link VideoDecoderOutputBufferRenderer} that will render frames in this view. */ getVideoDecoderOutputBufferRenderer()54 public VideoDecoderOutputBufferRenderer getVideoDecoderOutputBufferRenderer() { 55 return renderer; 56 } 57 } 58