下面列出了android.graphics.SurfaceTexture#OnFrameAvailableListener ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@TargetApi(21)
private static void setOnFrameAvailableListener(
SurfaceTexture surfaceTexture,
SurfaceTexture.OnFrameAvailableListener listener,
Handler handler) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
surfaceTexture.setOnFrameAvailableListener(listener, handler);
} else {
// The documentation states that the listener will be called on an arbitrary thread, but
// in
// pratice, it is always the thread on which the SurfaceTexture was constructed. There
// are
// assertions in place in case this ever changes. For API >= 21, we use the new API to
// explicitly specify the handler.
surfaceTexture.setOnFrameAvailableListener(listener);
}
}
@TargetApi(21)
private static void setOnFrameAvailableListener(SurfaceTexture surfaceTexture,
SurfaceTexture.OnFrameAvailableListener listener, Handler handler) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
surfaceTexture.setOnFrameAvailableListener(listener, handler);
} else {
// The documentation states that the listener will be called on an arbitrary thread, but in
// pratice, it is always the thread on which the SurfaceTexture was constructed. There are
// assertions in place in case this ever changes. For API >= 21, we use the new API to
// explicitly specify the handler.
surfaceTexture.setOnFrameAvailableListener(listener);
}
}
/**
* Creates instances of TextureRender and SurfaceTexture, and a Surface associated
* with the SurfaceTexture.
*/
private void setup(SurfaceTexture.OnFrameAvailableListener listener) {
mTextureRender = new FrameBufferObjectRenderer(mFilter);
mTextureRender.surfaceCreated();
// Even if we don't access the SurfaceTexture after the constructor returns, we
// still need to keep a reference to it. The Surface doesn't retain a reference
// at the Java level, so if we don't either then the object can get GCed, which
// causes the native finalizer to run.
if (VERBOSE) Log.d(TAG, "textureID=" + mTextureRender.getTextureId());
mSurfaceTexture = new SurfaceTexture(mTextureRender.getTextureId());
// This doesn't work if OutputSurface is created on the thread that CTS started for
// these test cases.
//
// The CTS-created thread has a Looper, and the SurfaceTexture constructor will
// create a Handler that uses it. The "frame available" message is delivered
// there, but since we're not a Looper-based thread we'll never see it. For
// this to do anything useful, OutputSurface must be created on a thread without
// a Looper, so that SurfaceTexture uses the main application Looper instead.
//
// Java language note: passing "this" out of a constructor is generally unwise,
// but we should be able to get away with it here.
mSurfaceTexture.setOnFrameAvailableListener(listener);
mSurface = new Surface(mSurfaceTexture);
checkEglError("setup");
}
@TargetApi(21)
private static void setOnFrameAvailableListener(SurfaceTexture surfaceTexture, SurfaceTexture.OnFrameAvailableListener listener, Handler handler) {
if (Build.VERSION.SDK_INT >= 21) {
surfaceTexture.setOnFrameAvailableListener(listener, handler);
} else {
surfaceTexture.setOnFrameAvailableListener(listener);
}
}
public void setOnFrameAvailableListener(final SurfaceTexture.OnFrameAvailableListener l) {
onFrameAvailableListener = l;
}
public void setOnFrameAvailableListener(final SurfaceTexture.OnFrameAvailableListener l) {
onFrameAvailableListener = l;
}
public OutputSurface(final SurfaceTexture.OnFrameAvailableListener listener) {
setup(listener);
}
public void setOnFrameAvailableListener(final SurfaceTexture.OnFrameAvailableListener l) {
onFrameAvailableListener = l;
}
public void setOnFrameAvailableListener(SurfaceTexture.OnFrameAvailableListener l) {
mOnFrameAvailableListener = l;
}