Java Code Examples for android.view.TextureView#setSurfaceTextureListener()

The following examples show how to use android.view.TextureView#setSurfaceTextureListener() . 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: PlayMovieActivity.java    From pause-resume-video-recording with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_play_movie);

    mTextureView = (TextureView) findViewById(R.id.movie_texture_view);
    mTextureView.setSurfaceTextureListener(this);

    // Populate file-selection spinner.
    Spinner spinner = (Spinner) findViewById(R.id.playMovieFile_spinner);
    // Need to create one of these fancy ArrayAdapter thingies, and specify the generic layout
    // for the widget itself.
    mMovieFiles = MiscUtils.getFiles(Environment.getExternalStorageDirectory(), "*.mp4");
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item, mMovieFiles);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    // Apply the adapter to the spinner.
    spinner.setAdapter(adapter);
    spinner.setOnItemSelectedListener(this);

    updateControls();
}
 
Example 2
Source File: FimiH264Video.java    From FimiX8-RE with MIT License 6 votes vote down vote up
public void init() {
    this.mVideoWidth = 0;
    this.mVideoHeight = 0;
    setBackgroundColor(ViewCompat.MEASURED_STATE_MASK);
    setFocusable(true);
    setFocusableInTouchMode(true);
    requestFocus();
    this.mCurrentState = 0;
    this.mTargetState = 0;
    TextureView renderUIView = new TextureView(getContext());
    renderUIView.setLayoutParams(new LayoutParams(-2, -2, 17));
    renderUIView.setSurfaceTextureListener(this.mSurfaceCallback);
    this.mX8Camera9GridView = new X8Camera9GridView(getContext());
    this.mX8Camera9GridView.setLayoutParams(new LayoutParams(-1, -1, 17));
    this.mX8AiTrackContainterView = new X8AiTrackContainterView(getContext());
    this.mX8AiTrackContainterView.setLayoutParams(new LayoutParams(-1, -1, 17));
    this.blackView = new View(getContext());
    this.blackView.setLayoutParams(new LayoutParams(-1, -1, 17));
    this.blackView.setBackgroundColor(getContext().getResources().getColor(R.color.black));
    addView(renderUIView);
    addView(this.mX8AiTrackContainterView);
    addView(this.blackView);
    addView(this.mX8Camera9GridView);
    showGridLine(GlobalConfig.getInstance().getGridLine());
}
 
Example 3
Source File: SimpleVideoPlayer.java    From SimpleVideoEditor with Apache License 2.0 5 votes vote down vote up
/**
 * 开始播放
 *
 * @param request 播放的请求
 */
public void start(PlayRequest request) {
    if (mCurrentState != STATE_IDLE) {
        log("start on wrong state: " + mCurrentState);
        return;
    }

    if (request.videoSource == null) {
        log("null source is not allowed!");
        return;
    }

    mTextureView = new TextureView(getContext());
    // Instantiate and add TextureView for rendering
    final LayoutParams textureLp =
            new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.MATCH_PARENT);
    textureLp.gravity = Gravity.CENTER;
    // 放在z轴最下面,防止盖住控制view
    addView(mTextureView, 0, textureLp);
    mTextureView.setSurfaceTextureListener(this);
    log("Add texture view");

    mSource = request.videoSource;
    mInitialPosition = request.startPos;
    mLoop = request.loop;
    mLeftVolume = request.leftVolume;
    mRightVolume = request.rightVolume;
    prepare();
}
 
Example 4
Source File: CameraView.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public CameraView(Context context, boolean frontface) {
    super(context, null);
    initialFrontface = isFrontface = frontface;
    textureView = new TextureView(context);
    textureView.setSurfaceTextureListener(this);
    addView(textureView);
    focusAreaSize = AndroidUtilities.dp(96);
    outerPaint.setColor(0xffffffff);
    outerPaint.setStyle(Paint.Style.STROKE);
    outerPaint.setStrokeWidth(AndroidUtilities.dp(2));
    innerPaint.setColor(0x7fffffff);
}
 
Example 5
Source File: TutorialFragment.java    From shortrain with MIT License 5 votes vote down vote up
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    if (mediaPlayer == null) {
        TextureView textureView = (TextureView) view.findViewById(R.id.tutorial_view_texture_view);
        textureView.setSurfaceTextureListener(this);
    }

    int textId = getArguments().getInt(TEXT_RES_ID);
    TextView textView = (TextView) view.findViewById(R.id.tutorial_view_text_view);
    textView.setOnClickListener((OnNextSlideClicked) getActivity());
    textView.setText(textId);
}
 
Example 6
Source File: CameraView.java    From KrGallery with GNU General Public License v2.0 5 votes vote down vote up
public CameraView(Context context, boolean frontface) {
    super(context, null);
    isFrontface = frontface;
    textureView = new TextureView(context);
    textureView.setSurfaceTextureListener(this);
    addView(textureView);
    focusAreaSize = AndroidUtilities.dp(96);
    outerPaint.setColor(0xffffffff);
    outerPaint.setStyle(Paint.Style.STROKE);
    outerPaint.setStrokeWidth(AndroidUtilities.dp(2));
    innerPaint.setColor(0x7fffffff);
}
 
Example 7
Source File: VideoOverlay.java    From backgroundvideo with GNU General Public License v3.0 5 votes vote down vote up
public VideoOverlay(Context context) {
    super(context);

    this.setClickable(false);
    this.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));

    // Create surface to display the camera preview
    mPreview = new TextureView(context);
    mPreview.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    mPreview.setClickable(false);
    mPreview.setSurfaceTextureListener(this);
    attachView();
}
 
Example 8
Source File: ExoFFmpegPlayer.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
@Override
public void setVideoTextureView(TextureView textureView) {
    clearListener();
    this.textureView = textureView;
    this.setVideoTextureView(textureView);

    if (textureView.isAvailable()) {
        onSurfaceSizeChanged(textureView.getWidth(), textureView.getHeight());
    }
    textureView.setSurfaceTextureListener(new InnerSurfaceTextureListener(textureView.getSurfaceTextureListener()));
}
 
Example 9
Source File: SimpleExoPlayer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void setVideoTextureView(TextureView textureView) {
  if (this.textureView == textureView) {
    return;
  }
  removeSurfaceCallbacks();
  this.textureView = textureView;
  needSetSurface = true;
  if (textureView == null) {
    setVideoSurfaceInternal(null, true);
    maybeNotifySurfaceSizeChanged(/* width= */ 0, /* height= */ 0);
  } else {
    if (textureView.getSurfaceTextureListener() != null) {
      Log.w(TAG, "Replacing existing SurfaceTextureListener.");
    }
    textureView.setSurfaceTextureListener(componentListener);
    SurfaceTexture surfaceTexture = textureView.isAvailable() ? textureView.getSurfaceTexture()
        : null;
    if (surfaceTexture == null) {
      setVideoSurfaceInternal(/* surface= */ null, /* ownsSurface= */ true);
      maybeNotifySurfaceSizeChanged(/* width= */ 0, /* height= */ 0);
    } else {
      setVideoSurfaceInternal(new Surface(surfaceTexture), /* ownsSurface= */ true);
      maybeNotifySurfaceSizeChanged(textureView.getWidth(), textureView.getHeight());
    }
  }
}
 
Example 10
Source File: LiveCameraActivity.java    From pause-resume-video-recording with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mTextureView = new TextureView(this);
    mTextureView.setSurfaceTextureListener(this);

    setContentView(mTextureView);
}
 
Example 11
Source File: TextureViewCanvasActivity.java    From pause-resume-video-recording with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.d(TAG, "onCreate");
    super.onCreate(savedInstanceState);

    // Start up the Renderer thread.  It'll sleep until the TextureView is ready.
    mRenderer = new Renderer();
    mRenderer.start();

    setContentView(R.layout.activity_texture_view_canvas);
    mTextureView = (TextureView) findViewById(R.id.canvasTextureView);
    mTextureView.setSurfaceTextureListener(mRenderer);
}
 
Example 12
Source File: MediaPlayerFragment.java    From kickflip-android-sdk with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View root = inflater.inflate(R.layout.fragment_media_player, container, false);
    if (root != null) {
        mTextureView = (TextureView) root.findViewById(R.id.textureView);
        mTextureView.setSurfaceTextureListener(this);
        mProgress = (ProgressBar) root.findViewById(R.id.progress);
        mLiveLabel = (TextView) root.findViewById(R.id.liveLabel);
    }
    return root;
}
 
Example 13
Source File: PlaybackView.java    From justaline-android with Apache License 2.0 5 votes vote down vote up
private void init() {

        inflate(getContext(), R.layout.view_playback, this);

        setBackgroundColor(Color.BLACK);

        mAnalytics = Fa.get();

        TextureView mVideoTextureView = findViewById(R.id.video);
        mVideoTextureView.setSurfaceTextureListener(this);

        findViewById(R.id.close_button).setOnClickListener(this);
        findViewById(R.id.layout_share).setOnClickListener(this);
        findViewById(R.id.layout_save).setOnClickListener(this);

        // set margin of bottom icons to be appropriate size for screen
        View saveLayout = findViewById(R.id.layout_save);
        ConstraintLayout.LayoutParams layoutParams = (ConstraintLayout.LayoutParams) saveLayout
                .getLayoutParams();
        layoutParams.bottomMargin = getHeightOfNavigationBar();
        saveLayout.setLayoutParams(layoutParams);

        View shareLayout = findViewById(R.id.layout_share);
        layoutParams = (ConstraintLayout.LayoutParams) shareLayout.getLayoutParams();
        layoutParams.bottomMargin = getHeightOfNavigationBar();
        shareLayout.setLayoutParams(layoutParams);

        mAudioAttributes = new AudioAttributes.Builder()
                .setUsage(AudioAttributes.USAGE_MEDIA)
                .setContentType(AudioAttributes.CONTENT_TYPE_MOVIE)
                .build();

    }
 
Example 14
Source File: SimpleExoPlayer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void setVideoTextureView(TextureView textureView) {
  if (this.textureView == textureView) {
    return;
  }
  removeSurfaceCallbacks();
  this.textureView = textureView;
  needSetSurface = true;
  if (textureView == null) {
    setVideoSurfaceInternal(null, true);
    maybeNotifySurfaceSizeChanged(/* width= */ 0, /* height= */ 0);
  } else {
    if (textureView.getSurfaceTextureListener() != null) {
      Log.w(TAG, "Replacing existing SurfaceTextureListener.");
    }
    textureView.setSurfaceTextureListener(componentListener);
    SurfaceTexture surfaceTexture = textureView.isAvailable() ? textureView.getSurfaceTexture()
        : null;
    if (surfaceTexture == null) {
      setVideoSurfaceInternal(/* surface= */ null, /* ownsSurface= */ true);
      maybeNotifySurfaceSizeChanged(/* width= */ 0, /* height= */ 0);
    } else {
      setVideoSurfaceInternal(new Surface(surfaceTexture), /* ownsSurface= */ true);
      maybeNotifySurfaceSizeChanged(textureView.getWidth(), textureView.getHeight());
    }
  }
}
 
Example 15
Source File: CameraView.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public CameraView(Context context, boolean frontface) {
    super(context, null);
    initialFrontface = isFrontface = frontface;
    textureView = new TextureView(context);
    textureView.setSurfaceTextureListener(this);
    addView(textureView);
    focusAreaSize = AndroidUtilities.dp(96);
    outerPaint.setColor(0xffffffff);
    outerPaint.setStyle(Paint.Style.STROKE);
    outerPaint.setStrokeWidth(AndroidUtilities.dp(2));
    innerPaint.setColor(0x7fffffff);
}
 
Example 16
Source File: SimpleExoPlayer.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void setVideoTextureView(TextureView textureView) {
  if (this.textureView == textureView) {
    return;
  }
  verifyApplicationThread();
  removeSurfaceCallbacks();
  this.textureView = textureView;
  needSetSurface = true;
  if (textureView == null) {
    setVideoSurfaceInternal(null, true);
    maybeNotifySurfaceSizeChanged(/* width= */ 0, /* height= */ 0);
  } else {
    if (textureView.getSurfaceTextureListener() != null) {
      Log.w(TAG, "Replacing existing SurfaceTextureListener.");
    }
    textureView.setSurfaceTextureListener(componentListener);
    SurfaceTexture surfaceTexture = textureView.isAvailable() ? textureView.getSurfaceTexture()
        : null;
    if (surfaceTexture == null) {
      setVideoSurfaceInternal(/* surface= */ null, /* ownsSurface= */ true);
      maybeNotifySurfaceSizeChanged(/* width= */ 0, /* height= */ 0);
    } else {
      setVideoSurfaceInternal(new Surface(surfaceTexture), /* ownsSurface= */ true);
      maybeNotifySurfaceSizeChanged(textureView.getWidth(), textureView.getHeight());
    }
  }
}
 
Example 17
Source File: KSYFloatingWindowView.java    From KSYMediaPlayer_Android with Apache License 2.0 5 votes vote down vote up
private void init(Context context) {
    mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    LayoutInflater.from(context).inflate(R.layout.floating_window, this);

    mTextureView = (TextureView) findViewById(R.id.floating_window_player_view);
    mQuit = (ImageView) findViewById(R.id.floating_window_quit);

    mTextureView.setSurfaceTextureListener(mSurfaceTextureListener);
    mQuit.setOnClickListener(mOnClickListener);
}
 
Example 18
Source File: PlayerActivity.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
private void initViews() {
    mVideoView = (TextureView) findViewById(R.id.video_view);
    mTimeView = (TextView) findViewById(R.id.video_time_view);
    mProgressView = (SeekBar) findViewById(R.id.video_progress_view);
    mControlBtn = (ImageButton) findViewById(R.id.video_control_btn);
    mPlayTipView = (TextView) findViewById(R.id.play_tip_view);

    mControlBtn.setOnClickListener(this);
    mVideoView.setSurfaceTextureListener(mSurfaceTextureListener);
    mProgressView.setOnSeekBarChangeListener(mSeekBarChangeListener);
}
 
Example 19
Source File: DownloadPlayActivity.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
private void initViews() {
    mVideoView = (TextureView) findViewById(R.id.download_video_view);
    mProgressView = (SeekBar) findViewById(R.id.download_progress_view);
    mControlBtn = (ImageButton) findViewById(R.id.download_control_btn);
    mTimeView = (TextView) findViewById(R.id.download_time_view);

    mVideoView.setSurfaceTextureListener(mSurfaceTextureListener);
    mControlBtn.setOnClickListener(this);
    mProgressView.setOnSeekBarChangeListener(mSeekBarChangeListener);
}
 
Example 20
Source File: MainActivity.java    From AndroidPlayground with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    final TextureView textureView = (TextureView) findViewById(R.id.mSurface);
    textureView.setSurfaceTextureListener(this);
    final TextView textView = (TextView) findViewById(R.id.mText);

    findViewById(R.id.mBtnSwitch).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mCamera.stopPreview();
            mCamera.release();
            mIsFront = !mIsFront;
            mCamera = Camera.open(mIsFront ? Camera.CameraInfo.CAMERA_FACING_FRONT
                    : Camera.CameraInfo.CAMERA_FACING_BACK);
            try {
                mCamera.setPreviewTexture(textureView.getSurfaceTexture());
                mCamera.startPreview();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });
    findViewById(R.id.mBtn).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            int rotation = getWindowManager().getDefaultDisplay().getRotation();
            switch (rotation) {
                case Surface.ROTATION_0:
                    textView.setText("0°");
                    break;
                case Surface.ROTATION_90:
                    textView.setText("90°");
                    break;
                case Surface.ROTATION_180:
                    textView.setText("180°");
                    break;
                case Surface.ROTATION_270:
                    textView.setText("270°");
                    break;
                default:
                    textView.setText("unknown");
                    break;
            }
            Camera.CameraInfo info = new Camera.CameraInfo();
            Camera.getCameraInfo(mIsFront ? Camera.CameraInfo.CAMERA_FACING_FRONT
                    : Camera.CameraInfo.CAMERA_FACING_BACK, info);
            textView.setText(textView.getText() + "\n" + info.orientation);
        }
    });
}