Java Code Examples for android.graphics.SurfaceTexture#release()

The following examples show how to use android.graphics.SurfaceTexture#release() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AAH_CustomVideoView.java    From AutoplayVideos with Apache License 2.0 6 votes vote down vote up
@Override
    public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
//        Log.d("k9k9", "onSurfaceTextureDestroyed: ");
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            //pre lollipop needs SurfaceTexture it owns before calling onDetachedFromWindow super
            surface.release();
        }
        if (mMediaPlayer != null) {
            mMediaPlayer.stop();
            mMediaPlayer.release();
            mMediaPlayer = null;
        }

        try {
            showThumb.call();
        } catch (Exception e) {
            e.printStackTrace();
        }

        return true;
    }
 
Example 2
Source File: ReleasePlayerTask.java    From Mrthumb with Apache License 2.0 5 votes vote down vote up
@Override
protected Object doInBackground(Object[] objects) {
    LogUtil.d("ReleasePlayerTask doInBackground");
    AudioManager audioManager = audioManagerWeakReference.get();
    if (audioManager != null) {
        audioManager.abandonAudioFocus(null);
        audioManagerWeakReference.clear();
        audioManagerWeakReference = null;
        LogUtil.d("ReleasePlayerTask release audioManager");
    }
    IMediaPlayer iMediaPlayer = mediaPlayerWeakReference.get();
    if (iMediaPlayer != null) {
        iMediaPlayer.release();
        mediaPlayerWeakReference.clear();
        mediaPlayerWeakReference = null;
        LogUtil.d("ReleasePlayerTask release iMediaPlayer");
    }
    SurfaceTexture surfaceTexture = surfaceTextureWeakReference.get();
    if (surfaceTexture != null) {
        surfaceTexture.release();
        surfaceTextureWeakReference.clear();
        surfaceTextureWeakReference = null;
        LogUtil.d("ReleasePlayerTask release surfaceTexture");
    }
    Surface surface = surfaceWeakReference.get();
    if (surface != null) {
        surface.release();
        surfaceWeakReference.clear();
        surfaceWeakReference = null;
        LogUtil.d("ReleasePlayerTask release surface");
    }
    return null;
}
 
Example 3
Source File: ExoTextureVideoView.java    From ExoMedia with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture) {
    delegate.onSurfaceDestroyed();
    surfaceTexture.release();

    return true;
}
 
Example 4
Source File: TextureRenderView.java    From ZZShow with Apache License 2.0 5 votes vote down vote up
@Override
public void releaseSurfaceTexture(SurfaceTexture surfaceTexture) {
    if (surfaceTexture == null) {
        Log.d(TAG, "releaseSurfaceTexture: null");
    } else if (mDidDetachFromWindow) {
        if (surfaceTexture != mSurfaceTexture) {
            Log.d(TAG, "releaseSurfaceTexture: didDetachFromWindow(): release different SurfaceTexture");
            surfaceTexture.release();
        } else if (!mOwnSurfaceTexture) {
            Log.d(TAG, "releaseSurfaceTexture: didDetachFromWindow(): release detached SurfaceTexture");
            surfaceTexture.release();
        } else {
            Log.d(TAG, "releaseSurfaceTexture: didDetachFromWindow(): already released by TextureView");
        }
    } else if (mWillDetachFromWindow) {
        if (surfaceTexture != mSurfaceTexture) {
            Log.d(TAG, "releaseSurfaceTexture: willDetachFromWindow(): release different SurfaceTexture");
            surfaceTexture.release();
        } else if (!mOwnSurfaceTexture) {
            Log.d(TAG, "releaseSurfaceTexture: willDetachFromWindow(): re-attach SurfaceTexture to TextureView");
            setOwnSurfaceTexture(true);
        } else {
            Log.d(TAG, "releaseSurfaceTexture: willDetachFromWindow(): will released by TextureView");
        }
    } else {
        if (surfaceTexture != mSurfaceTexture) {
            Log.d(TAG, "releaseSurfaceTexture: alive: release different SurfaceTexture");
            surfaceTexture.release();
        } else if (!mOwnSurfaceTexture) {
            Log.d(TAG, "releaseSurfaceTexture: alive: re-attach SurfaceTexture to TextureView");
            setOwnSurfaceTexture(true);
        } else {
            Log.d(TAG, "releaseSurfaceTexture: alive: will released by TextureView");
        }
    }
}
 
Example 5
Source File: GifTextureView.java    From sketch with Apache License 2.0 5 votes vote down vote up
@Override
protected void onDetachedFromWindow() {
	mRenderThread.dispose(this, null);
	super.onDetachedFromWindow();
	final SurfaceTexture surfaceTexture = getSurfaceTexture();
	if (surfaceTexture != null) {
		surfaceTexture.release();
	}
}
 
Example 6
Source File: ListPlayAdapter.java    From BlogDemo with Apache License 2.0 5 votes vote down vote up
@Override public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
  if (mPlayer != null) {
    mPlayer.stop();
  }
  surface.release();
  mPlayer = null;
  return true;
}
 
Example 7
Source File: PlayerViewSurfaceHolder.java    From no-player with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
    setSurfaceNotReady();
    surface.release();
    callbacks.clear();
    return true;
}
 
Example 8
Source File: GifTextureView.java    From android-gif-drawable-eclipse-sample with MIT License 5 votes vote down vote up
@Override
protected void onDetachedFromWindow() {
    mRenderThread.dispose();
    super.onDetachedFromWindow();
    final SurfaceTexture surfaceTexture = getSurfaceTexture();
    if (surfaceTexture != null) {
        surfaceTexture.release();
    }
}
 
Example 9
Source File: TextureRenderView.java    From talk-android with MIT License 5 votes vote down vote up
@Override
public void releaseSurfaceTexture(SurfaceTexture surfaceTexture) {
    if (surfaceTexture == null) {
        Log.d(TAG, "releaseSurfaceTexture: null");
        return;
    } else if (mDidDetachFromWindow) {
        if (surfaceTexture != mSurfaceTexture) {
            Log.d(TAG, "releaseSurfaceTexture: didDetachFromWindow(): release different SurfaceTexture");
            surfaceTexture.release();
        } else if (!mOwnSurfaceTexture) {
            Log.d(TAG, "releaseSurfaceTexture: didDetachFromWindow(): release detached SurfaceTexture");
            surfaceTexture.release();
        } else {
            Log.d(TAG, "releaseSurfaceTexture: didDetachFromWindow(): already released by TextureView");
        }
    } else if (mWillDetachFromWindow) {
        if (surfaceTexture != mSurfaceTexture) {
            Log.d(TAG, "releaseSurfaceTexture: willDetachFromWindow(): release different SurfaceTexture");
            surfaceTexture.release();
        } else if (!mOwnSurfaceTexture) {
            Log.d(TAG, "releaseSurfaceTexture: willDetachFromWindow(): re-attach SurfaceTexture to TextureView");
            setOwnSurfaceTexture(true);
        } else {
            Log.d(TAG, "releaseSurfaceTexture: willDetachFromWindow(): will released by TextureView");
        }
    } else {
        if (surfaceTexture != mSurfaceTexture) {
            Log.d(TAG, "releaseSurfaceTexture: alive: release different SurfaceTexture");
            surfaceTexture.release();
        } else if (!mOwnSurfaceTexture) {
            Log.d(TAG, "releaseSurfaceTexture: alive: re-attach SurfaceTexture to TextureView");
            setOwnSurfaceTexture(true);
        } else {
            Log.d(TAG, "releaseSurfaceTexture: alive: will released by TextureView");
        }
    }
}
 
Example 10
Source File: TextureRenderView.java    From MVideo with Apache License 2.0 5 votes vote down vote up
@Override
public void releaseSurfaceTexture(SurfaceTexture surfaceTexture) {
    if (surfaceTexture == null) {
        Log.d(TAG, "releaseSurfaceTexture: null");
    } else if (mDidDetachFromWindow) {
        if (surfaceTexture != mSurfaceTexture) {
            Log.d(TAG, "releaseSurfaceTexture: didDetachFromWindow(): release different SurfaceTexture");
            surfaceTexture.release();
        } else if (!mOwnSurfaceTexture) {
            Log.d(TAG, "releaseSurfaceTexture: didDetachFromWindow(): release detached SurfaceTexture");
            surfaceTexture.release();
        } else {
            Log.d(TAG, "releaseSurfaceTexture: didDetachFromWindow(): already released by TextureView");
        }
    } else if (mWillDetachFromWindow) {
        if (surfaceTexture != mSurfaceTexture) {
            Log.d(TAG, "releaseSurfaceTexture: willDetachFromWindow(): release different SurfaceTexture");
            surfaceTexture.release();
        } else if (!mOwnSurfaceTexture) {
            Log.d(TAG, "releaseSurfaceTexture: willDetachFromWindow(): re-attach SurfaceTexture to TextureView");
            setOwnSurfaceTexture(true);
        } else {
            Log.d(TAG, "releaseSurfaceTexture: willDetachFromWindow(): will released by TextureView");
        }
    } else {
        if (surfaceTexture != mSurfaceTexture) {
            Log.d(TAG, "releaseSurfaceTexture: alive: release different SurfaceTexture");
            surfaceTexture.release();
        } else if (!mOwnSurfaceTexture) {
            Log.d(TAG, "releaseSurfaceTexture: alive: re-attach SurfaceTexture to TextureView");
            setOwnSurfaceTexture(true);
        } else {
            Log.d(TAG, "releaseSurfaceTexture: alive: will released by TextureView");
        }
    }
}
 
Example 11
Source File: TextureRenderView.java    From TvPlayer with Apache License 2.0 5 votes vote down vote up
@Override
public void releaseSurfaceTexture(SurfaceTexture surfaceTexture) {
    if (surfaceTexture == null) {
        Log.d(TAG, "releaseSurfaceTexture: null");
        return;
    } else if (mDidDetachFromWindow) {
        if (surfaceTexture != mSurfaceTexture) {
            Log.d(TAG, "releaseSurfaceTexture: didDetachFromWindow(): release different SurfaceTexture");
            surfaceTexture.release();
        } else if (!mOwnSurfaceTecture) {
            Log.d(TAG, "releaseSurfaceTexture: didDetachFromWindow(): release detached SurfaceTexture");
            surfaceTexture.release();
        } else {
            Log.d(TAG, "releaseSurfaceTexture: didDetachFromWindow(): already released by TextureView");
        }
    } else if (mWillDetachFromWindow) {
        if (surfaceTexture != mSurfaceTexture) {
            Log.d(TAG, "releaseSurfaceTexture: willDetachFromWindow(): release different SurfaceTexture");
            surfaceTexture.release();
        } else if (!mOwnSurfaceTecture) {
            Log.d(TAG, "releaseSurfaceTexture: willDetachFromWindow(): re-attach SurfaceTexture to TextureView");
            setOwnSurfaceTexture(true);
        } else {
            Log.d(TAG, "releaseSurfaceTexture: willDetachFromWindow(): will released by TextureView");
        }
    } else {
        if (surfaceTexture != mSurfaceTexture) {
            Log.d(TAG, "releaseSurfaceTexture: alive: release different SurfaceTexture");
            surfaceTexture.release();
        } else if (!mOwnSurfaceTecture) {
            Log.d(TAG, "releaseSurfaceTexture: alive: re-attach SurfaceTexture to TextureView");
            setOwnSurfaceTexture(true);
        } else {
            Log.d(TAG, "releaseSurfaceTexture: alive: will released by TextureView");
        }
    }
}
 
Example 12
Source File: TextureRenderView.java    From WliveTV with Apache License 2.0 5 votes vote down vote up
@Override
public void releaseSurfaceTexture(SurfaceTexture surfaceTexture) {
    if (surfaceTexture == null) {
        Log.d(TAG, "releaseSurfaceTexture: null");
        return;
    } else if (mDidDetachFromWindow) {
        if (surfaceTexture != mSurfaceTexture) {
            Log.d(TAG, "releaseSurfaceTexture: didDetachFromWindow(): release different SurfaceTexture");
            surfaceTexture.release();
        } else if (!mOwnSurfaceTecture) {
            Log.d(TAG, "releaseSurfaceTexture: didDetachFromWindow(): release detached SurfaceTexture");
            surfaceTexture.release();
        } else {
            Log.d(TAG, "releaseSurfaceTexture: didDetachFromWindow(): already released by TextureView");
        }
    } else if (mWillDetachFromWindow) {
        if (surfaceTexture != mSurfaceTexture) {
            Log.d(TAG, "releaseSurfaceTexture: willDetachFromWindow(): release different SurfaceTexture");
            surfaceTexture.release();
        } else if (!mOwnSurfaceTecture) {
            Log.d(TAG, "releaseSurfaceTexture: willDetachFromWindow(): re-attach SurfaceTexture to TextureView");
            setOwnSurfaceTexture(true);
        } else {
            Log.d(TAG, "releaseSurfaceTexture: willDetachFromWindow(): will released by TextureView");
        }
    } else {
        if (surfaceTexture != mSurfaceTexture) {
            Log.d(TAG, "releaseSurfaceTexture: alive: release different SurfaceTexture");
            surfaceTexture.release();
        } else if (!mOwnSurfaceTecture) {
            Log.d(TAG, "releaseSurfaceTexture: alive: re-attach SurfaceTexture to TextureView");
            setOwnSurfaceTexture(true);
        } else {
            Log.d(TAG, "releaseSurfaceTexture: alive: will released by TextureView");
        }
    }
}
 
Example 13
Source File: TextureRenderView.java    From ShareBox with Apache License 2.0 5 votes vote down vote up
@Override
public void releaseSurfaceTexture(SurfaceTexture surfaceTexture) {
    if (surfaceTexture == null) {
        Log.d(TAG, "releaseSurfaceTexture: null");
    } else if (mDidDetachFromWindow) {
        if (surfaceTexture != mSurfaceTexture) {
            Log.d(TAG, "releaseSurfaceTexture: didDetachFromWindow(): release different SurfaceTexture");
            surfaceTexture.release();
        } else if (!mOwnSurfaceTexture) {
            Log.d(TAG, "releaseSurfaceTexture: didDetachFromWindow(): release detached SurfaceTexture");
            surfaceTexture.release();
        } else {
            Log.d(TAG, "releaseSurfaceTexture: didDetachFromWindow(): already released by TextureView");
        }
    } else if (mWillDetachFromWindow) {
        if (surfaceTexture != mSurfaceTexture) {
            Log.d(TAG, "releaseSurfaceTexture: willDetachFromWindow(): release different SurfaceTexture");
            surfaceTexture.release();
        } else if (!mOwnSurfaceTexture) {
            Log.d(TAG, "releaseSurfaceTexture: willDetachFromWindow(): re-attach SurfaceTexture to TextureView");
            setOwnSurfaceTexture(true);
        } else {
            Log.d(TAG, "releaseSurfaceTexture: willDetachFromWindow(): will released by TextureView");
        }
    } else {
        if (surfaceTexture != mSurfaceTexture) {
            Log.d(TAG, "releaseSurfaceTexture: alive: release different SurfaceTexture");
            surfaceTexture.release();
        } else if (!mOwnSurfaceTexture) {
            Log.d(TAG, "releaseSurfaceTexture: alive: re-attach SurfaceTexture to TextureView");
            setOwnSurfaceTexture(true);
        } else {
            Log.d(TAG, "releaseSurfaceTexture: alive: will released by TextureView");
        }
    }
}
 
Example 14
Source File: RendererHolder.java    From UVCCameraZxing with Apache License 2.0 4 votes vote down vote up
@Override
public void run() {
	if (DEBUG) Log.v(TAG, "start:threadid=" + Thread.currentThread().getId());
	mMasterEgl = new EGLBase(EGL14.EGL_NO_CONTEXT, false, false);
   	mDummySurface = mMasterEgl.createOffscreen(2, 2);
	mDummySurface.makeCurrent();
	mTexId = GLDrawer2D.initTex();
	mMasterTexture = new SurfaceTexture(mTexId);
	mSurface = new Surface(mMasterTexture);
	mMasterTexture.setOnFrameAvailableListener(mOnFrameAvailableListener);
	if (mCallback != null) {
		mCallback.onCreate(mSurface);
	}
	synchronized (mSync) {
		mMasterTexture.setDefaultBufferSize(mFrameWidth, mFrameHeight);
		isRunning = true;
		mSync.notifyAll();
		for ( ; isRunning ; ) {
			if (requestResize) {
				requestResize = false;
				if ((mRequestWidth > 0) && (mRequestHeight > 0)
					&& ((mFrameWidth != mRequestWidth) || (mFrameHeight != mRequestHeight))) {
					mFrameWidth = mRequestWidth;
					mFrameHeight = mRequestHeight;
					mMasterTexture.setDefaultBufferSize(mFrameWidth, mFrameHeight);
				}
			}
			if (requestDraw) {
				requestDraw = false;
				draw();
			} else {
				try {
					mSync.wait();
				} catch (final InterruptedException e) {
					break;
				}
			}
		}
	}
	if (DEBUG) Log.v(TAG, "finishing");
	if (mCallback != null) {
		mCallback.onDestroy();
	}
	release();
	mSurface = null;
	mMasterTexture.release();
	mMasterTexture = null;
	GLDrawer2D.deleteTex(mTexId);
	mDummySurface.release();
	mDummySurface = null;
	mMasterEgl.release();
	mMasterEgl = null;
	if (DEBUG) Log.v(TAG, "finished");
}
 
Example 15
Source File: JCVideoPlayer.java    From JieCaoVideoPlayer-develop with MIT License 4 votes vote down vote up
@Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
    surface.release();
    return true;
}
 
Example 16
Source File: NativeTextureVideoView.java    From ExoMedia with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
    surface.release();
    suspend();
    return true;
}
 
Example 17
Source File: ARTSurfaceViewShadowNode.java    From react-native-GPay with MIT License 4 votes vote down vote up
@Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
  surface.release();
  mSurface = null;
  return true;
}
 
Example 18
Source File: TextureViewGLActivity.java    From grafika with Apache License 2.0 4 votes vote down vote up
@Override
public void run() {
    while (true) {
        SurfaceTexture surfaceTexture = null;

        // Latch the SurfaceTexture when it becomes available.  We have to wait for
        // the TextureView to create it.
        synchronized (mLock) {
            while (!mDone && (surfaceTexture = mSurfaceTexture) == null) {
                try {
                    mLock.wait();
                } catch (InterruptedException ie) {
                    throw new RuntimeException(ie);     // not expected
                }
            }
            if (mDone) {
                break;
            }
        }
        Log.d(TAG, "Got surfaceTexture=" + surfaceTexture);

        // Create an EGL surface for our new SurfaceTexture.  We're not on the same
        // thread as the SurfaceTexture, which is a concern for the *consumer*, which
        // wants to call updateTexImage().  Because we're the *producer*, i.e. the
        // one generating the frames, we don't need to worry about being on the same
        // thread.
        mEglCore = new EglCore(null, EglCore.FLAG_TRY_GLES3);
        WindowSurface windowSurface = new WindowSurface(mEglCore, mSurfaceTexture);
        windowSurface.makeCurrent();

        // Render frames until we're told to stop or the SurfaceTexture is destroyed.
        doAnimation(windowSurface);

        windowSurface.release();
        mEglCore.release();
        if (!sReleaseInCallback) {
            Log.i(TAG, "Releasing SurfaceTexture in renderer thread");
            surfaceTexture.release();
        }
    }

    Log.d(TAG, "Renderer thread exiting");
}
 
Example 19
Source File: TextureViewGLActivity.java    From pause-resume-video-recording with Apache License 2.0 4 votes vote down vote up
@Override
public void run() {
    while (true) {
        SurfaceTexture surfaceTexture = null;

        // Latch the SurfaceTexture when it becomes available.  We have to wait for
        // the TextureView to create it.
        synchronized (mLock) {
            while (!mDone && (surfaceTexture = mSurfaceTexture) == null) {
                try {
                    mLock.wait();
                } catch (InterruptedException ie) {
                    throw new RuntimeException(ie);     // not expected
                }
            }
            if (mDone) {
                break;
            }
        }
        Log.d(TAG, "Got surfaceTexture=" + surfaceTexture);

        // Create an EGL surface for our new SurfaceTexture.  We're not on the same
        // thread as the SurfaceTexture, which is a concern for the *consumer*, which
        // wants to call updateTexImage().  Because we're the *producer*, i.e. the
        // one generating the frames, we don't need to worry about being on the same
        // thread.
        mEglCore = new EglCore(null, EglCore.FLAG_TRY_GLES3);
        WindowSurface windowSurface = new WindowSurface(mEglCore, mSurfaceTexture);
        windowSurface.makeCurrent();

        // Render frames until we're told to stop or the SurfaceTexture is destroyed.
        doAnimation(windowSurface);

        windowSurface.release();
        mEglCore.release();
        if (!sReleaseInCallback) {
            Log.i(TAG, "Releasing SurfaceTexture in renderer thread");
            surfaceTexture.release();
        }
    }

    Log.d(TAG, "Renderer thread exiting");
}
 
Example 20
Source File: SurfaceTexturePlatformWrapper.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@CalledByNative
private static void destroy(SurfaceTexture surfaceTexture) {
    surfaceTexture.setOnFrameAvailableListener(null);
    surfaceTexture.release();
}