Code example for TextureView

Methods: invalidate, requestLayout, setKeepScreenOn, setOnClickListener, setSurfaceTextureListener

0
	} 
 
	public void setVideoURI(Uri uri) {
		mUri = uri;
		openVideo(); 
		mTextureView.requestLayout();
		mTextureView.invalidate();
	} 
 
	public void stopPlayBack() { 
		if (mMediaPlayer != null) {
			try { 
				Log.d("Debug", "mp released. " + mMediaPlayer.toString());
				mMediaPlayer.stop();
				mMediaPlayer.release();
				mMediaPlayer = null;
				mCurrentState = STATE_IDLE;
				mTargetState = STATE_IDLE;
			} catch (Exception e) {
				e.printStackTrace();
				mCurrentState = STATE_ERROR;
				mTargetState = STATE_ERROR;
			} 
 
		} 
	} 
 
	public void setTitle(String title) {
		mTitle.setText(title);
		Log.d("Debug", "set title");
	} 
 
	public void setDesc(String desc) {
		mDesc.setText(desc);
		Log.d("Debug", "set desc");
	} 
 
	public void setThumbnailVisibility(Boolean value) {
		if (!value) {
			mVideoThumb.setVisibility(View.GONE);
		} 
		else{ 
			mVideoThumb.setVisibility(View.VISIBLE);
		} 
	} 
 
	public void setThumbnail(int res) {
		mVideoThumb.setImageResource(res);
	} 
 
	public void openVideo() { 
		if (mUri == null) {
			// not ready for playback just yet, will try again later 
			Log.d("URI", "null ");
			return; 
		} 
		// we shouldn't clear the target state, because somebody might have 
		// called start() previously 
		release(false); 
		try { 
			mMediaPlayer = new MediaPlayer();
			Log.d("mp", "mp created. " + mMediaPlayer.toString());
			mMediaPlayer.setOnPreparedListener(mPreparedListener);
			mMediaPlayer.setOnCompletionListener(mCompletionListener);
			mTextureView.setKeepScreenOn(true);
			mTextureView.setOnClickListener(mClickListener);
			// setOnTouchListener(mTouchListener); 
			mTextureView.setSurfaceTextureListener(mSurfaceTextureListener);
		} catch (Exception e) {
			e.printStackTrace();
		} 
	}