接收网络传输的数据,并使用MediaCodec解码,解码之后,使用SurfaceView播放。
<MyGLSurfaceView
android:id="@+id/videoView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
定义Renderer渲染:
public class VideoRenderer implements GLSurfaceView.Renderer, SurfaceTexture.OnFrameAvailableListener{
private static final String TAG = "VideoRenderer";
private GLSurfaceViewHelper mHelper;
private int mWidth;
private int mHeight;
public VideoRenderer(int width, int height){
mWidth = width;
mHeight = height;
}
@Override
public void onFrameAvailable(SurfaceTexture surfaceTexture) {
//Log.d(TAG, "onFrameAvailable");
}
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
Log.d(TAG, "onSurfaceCreated");
if (mHelper == null) {
mHelper = new GLSurfaceViewHelper(this, mWidth, mHeight);
mHelper.init();
}
}
@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
Log.d(TAG, "onSurfaceChanged");
}
@Override
public void onDrawFrame(GL10 gl) {
//Log.d(TAG, "onDrawFrame");
if (mHelper != null) {
mHelper.render();
}
}
public Surface getSurface() {
Log.d(TAG, "getSurface");
return new Surface(mHelper.getSurfaceTexture());
}
}
主要解码逻辑如下:
public class VideoDecoder extends Thread {
private stat