Java Code Examples for android.view.Surface#isValid()

The following examples show how to use android.view.Surface#isValid() . 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: SimpleExoPlayer.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
@Override
public void setVideoSurfaceHolder(@Nullable SurfaceHolder surfaceHolder) {
  verifyApplicationThread();
  removeSurfaceCallbacks();
  if (surfaceHolder != null) {
    clearVideoDecoderOutputBufferRenderer();
  }
  this.surfaceHolder = surfaceHolder;
  if (surfaceHolder == null) {
    setVideoSurfaceInternal(null, /* ownsSurface= */ false);
    maybeNotifySurfaceSizeChanged(/* width= */ 0, /* height= */ 0);
  } else {
    surfaceHolder.addCallback(componentListener);
    Surface surface = surfaceHolder.getSurface();
    if (surface != null && surface.isValid()) {
      setVideoSurfaceInternal(surface, /* ownsSurface= */ false);
      Rect surfaceSize = surfaceHolder.getSurfaceFrame();
      maybeNotifySurfaceSizeChanged(surfaceSize.width(), surfaceSize.height());
    } else {
      setVideoSurfaceInternal(/* surface= */ null, /* ownsSurface= */ false);
      maybeNotifySurfaceSizeChanged(/* width= */ 0, /* height= */ 0);
    }
  }
}
 
Example 2
Source File: RequestThreadManager.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private void resetJpegSurfaceFormats(Collection<Surface> surfaces) {
    if (!USE_BLOB_FORMAT_OVERRIDE || surfaces == null) {
        return;
    }
    for(Surface s : surfaces) {
        if (s == null || !s.isValid()) {
            Log.w(TAG, "Jpeg surface is invalid, skipping...");
            continue;
        }
        try {
            LegacyCameraDevice.setSurfaceFormat(s, LegacyMetadataMapper.HAL_PIXEL_FORMAT_BLOB);
        } catch (LegacyExceptionUtils.BufferQueueAbandonedException e) {
            Log.w(TAG, "Surface abandoned, skipping...", e);
        }
    }
}
 
Example 3
Source File: SimpleExoPlayer.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void setVideoSurfaceHolder(SurfaceHolder surfaceHolder) {
  removeSurfaceCallbacks();
  this.surfaceHolder = surfaceHolder;
  if (surfaceHolder == null) {
    setVideoSurfaceInternal(null, false);
    maybeNotifySurfaceSizeChanged(/* width= */ 0, /* height= */ 0);
  } else {
    surfaceHolder.addCallback(componentListener);
    Surface surface = surfaceHolder.getSurface();
    if (surface != null && surface.isValid()) {
      setVideoSurfaceInternal(surface, /* ownsSurface= */ false);
      Rect surfaceSize = surfaceHolder.getSurfaceFrame();
      maybeNotifySurfaceSizeChanged(surfaceSize.width(), surfaceSize.height());
    } else {
      setVideoSurfaceInternal(/* surface= */ null, /* ownsSurface= */ false);
      maybeNotifySurfaceSizeChanged(/* width= */ 0, /* height= */ 0);
    }
  }
}
 
Example 4
Source File: SimpleExoPlayer.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void setVideoSurfaceHolder(SurfaceHolder surfaceHolder) {
  removeSurfaceCallbacks();
  this.surfaceHolder = surfaceHolder;
  if (surfaceHolder == null) {
    setVideoSurfaceInternal(null, false);
    maybeNotifySurfaceSizeChanged(/* width= */ 0, /* height= */ 0);
  } else {
    surfaceHolder.addCallback(componentListener);
    Surface surface = surfaceHolder.getSurface();
    if (surface != null && surface.isValid()) {
      setVideoSurfaceInternal(surface, /* ownsSurface= */ false);
      Rect surfaceSize = surfaceHolder.getSurfaceFrame();
      maybeNotifySurfaceSizeChanged(surfaceSize.width(), surfaceSize.height());
    } else {
      setVideoSurfaceInternal(/* surface= */ null, /* ownsSurface= */ false);
      maybeNotifySurfaceSizeChanged(/* width= */ 0, /* height= */ 0);
    }
  }
}
 
Example 5
Source File: PlayerActivity.java    From android-tv-leanback with Apache License 2.0 6 votes vote down vote up
private void maybeStartPlayback() {
    Log.d(TAG, "maybeStartPlayback");
    Surface surface = surfaceView.getHolder().getSurface();
    if (videoRenderer == null || surface == null || !surface.isValid()) {
        // We're not ready yet.
        return;
    }
    player.sendMessage(videoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE, surface);
    if (autoPlay) {
        if (mIsOnTv) {
            // This will update the player controls and the activity will receive the callback
            // OnPlayPauseClickedListener.onFragmentPlayPause(Video, int, Boolean)
            mPlaybackOverlayFragment.pressPlay();
        } else {
            player.setPlayWhenReady(true);
        }
        autoPlay = false;
    }
}
 
Example 6
Source File: AWindow.java    From libvlc-sdk-android with GNU General Public License v2.0 5 votes vote down vote up
private void setSurface(int id, Surface surface, SurfaceHolder surfaceHolder) {
    ensureInitState();
    if (!surface.isValid() && surfaceHolder == null)
        throw new IllegalStateException("surface is not attached and holder is null");
    final SurfaceHelper surfaceHelper = mSurfaceHelpers[id];
    if (surfaceHelper != null)
        surfaceHelper.release();

    mSurfaceHelpers[id] = new SurfaceHelper(id, surface, surfaceHolder);
}
 
Example 7
Source File: SystemPlayerManager.java    From GSYVideoPlayer with Apache License 2.0 5 votes vote down vote up
@Override
public void showDisplay(Message msg) {
    if (msg.obj == null && mediaPlayer != null && !release) {
        mediaPlayer.setSurface(null);
    } else if (msg.obj != null) {
        Surface holder = (Surface) msg.obj;
        surface = holder;
        if (mediaPlayer != null && holder.isValid() && !release) {
            mediaPlayer.setSurface(holder);
        }
        if (!isPlaying) {
            pause();
        }
    }
}
 
Example 8
Source File: PlayerActivity.java    From android-tv-leanback with Apache License 2.0 5 votes vote down vote up
private void maybeStartPlayback() {
    Log.d(TAG, "maybeStartPlayback");
    Surface surface = surfaceView.getHolder().getSurface();
    if (videoRenderer == null || surface == null || !surface.isValid()) {
        // We're not ready yet.
        return;
    }
    player.sendMessage(videoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE, surface);
    if (autoPlay) {
        player.setPlayWhenReady(true);
        autoPlay = false;
    }
}
 
Example 9
Source File: AWindow.java    From vlc-example-streamplayer with GNU General Public License v3.0 5 votes vote down vote up
private void setSurface(Surface surface) {
    if (surface.isValid() && getNativeSurface(mId) == null) {
        mSurface = surface;
        setNativeSurface(mId, mSurface);
        onSurfaceCreated();
    }
}
 
Example 10
Source File: AWindow.java    From OTTLivePlayer_vlc with MIT License 5 votes vote down vote up
private void setSurface(int id, Surface surface, SurfaceHolder surfaceHolder) {
    ensureInitState();
    if (!surface.isValid() && surfaceHolder == null)
        throw new IllegalStateException("surface is not attached and holder is null");
    final SurfaceHelper surfaceHelper = mSurfaceHelpers[id];
    if (surfaceHelper != null)
        surfaceHelper.release();

    mSurfaceHelpers[id] = new SurfaceHelper(id, surface, surfaceHolder);
}
 
Example 11
Source File: MultiSurfaceActivity.java    From pause-resume-video-recording with Apache License 2.0 5 votes vote down vote up
private void startBouncing() {
    final Surface surface = mSurfaceView2.getHolder().getSurface();
    if (surface == null || !surface.isValid()) {
        Log.w(TAG, "mSurfaceView2 is not ready");
        return;
    }
    mBounceThread = new Thread() {
        @Override
        public void run() {
            while (true) {
                long startWhen = System.nanoTime();
                for (int i = 0; i < BOUNCE_STEPS; i++) {
                    if (!mBouncing) return;
                    drawBouncingCircle(surface, i);
                }
                for (int i = BOUNCE_STEPS; i > 0; i--) {
                    if (!mBouncing) return;
                    drawBouncingCircle(surface, i);
                }
                long duration = System.nanoTime() - startWhen;
                double framesPerSec = 1000000000.0 / (duration / (BOUNCE_STEPS * 2.0));
                Log.d(TAG, "Bouncing at " + framesPerSec + " fps");
            }
        }
    };
    mBouncing = true;
    mBounceThread.setName("Bouncer");
    mBounceThread.start();
}
 
Example 12
Source File: PlayerActivity.java    From android-tv-leanback with Apache License 2.0 5 votes vote down vote up
private void maybeStartPlayback() {
    Log.d(TAG, "maybeStartPlayback");
    Surface surface = surfaceView.getHolder().getSurface();
    if (videoRenderer == null || surface == null || !surface.isValid()) {
        // We're not ready yet.
        return;
    }
    player.sendMessage(videoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE, surface);
    if (autoPlay) {
        player.setPlayWhenReady(true);
        autoPlay = false;
    }
}
 
Example 13
Source File: MultiSurfaceActivity.java    From grafika with Apache License 2.0 5 votes vote down vote up
private void startBouncing() {
    final Surface surface = mSurfaceView2.getHolder().getSurface();
    if (surface == null || !surface.isValid()) {
        Log.w(TAG, "mSurfaceView2 is not ready");
        return;
    }
    mBounceThread = new Thread() {
        @Override
        public void run() {
            while (true) {
                long startWhen = System.nanoTime();
                for (int i = 0; i < BOUNCE_STEPS; i++) {
                    if (!mBouncing) return;
                    drawBouncingCircle(surface, i);
                }
                for (int i = BOUNCE_STEPS; i > 0; i--) {
                    if (!mBouncing) return;
                    drawBouncingCircle(surface, i);
                }
                long duration = System.nanoTime() - startWhen;
                double framesPerSec = 1000000000.0 / (duration / (BOUNCE_STEPS * 2.0));
                Log.d(TAG, "Bouncing at " + framesPerSec + " fps");
            }
        }
    };
    mBouncing = true;
    mBounceThread.setName("Bouncer");
    mBounceThread.start();
}
 
Example 14
Source File: IjkExo2MediaPlayer.java    From GSYVideoPlayer with Apache License 2.0 5 votes vote down vote up
@Override
public void setSurface(Surface surface) {
    mSurface = surface;
    if (mInternalPlayer != null) {
        if (surface != null && !surface.isValid()) {
            mSurface = null;
        }
        mInternalPlayer.setVideoSurface(surface);
    }
}
 
Example 15
Source File: AWindow.java    From VCL-Android with Apache License 2.0 5 votes vote down vote up
private void setSurface(int id, Surface surface, SurfaceHolder surfaceHolder) {
    ensureInitState();
    if (!surface.isValid() || surfaceHolder == null)
        throw new IllegalStateException("surface is not attached and holder is null");
    final SurfaceHelper surfaceHelper = mSurfaceHelpers[id];
    if (surfaceHelper != null)
        surfaceHelper.release();

    mSurfaceHelpers[id] = new SurfaceHelper(id, surface, surfaceHolder);
}
 
Example 16
Source File: AWindow.java    From libvlc-android-sdk with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void setSurface(Surface surface) {
    if (surface.isValid() && getNativeSurface(mId) == null) {
        mSurface = surface;
        setNativeSurface(mId, mSurface);
        onSurfaceCreated();
    }
}
 
Example 17
Source File: XMediaPlayer.java    From XPlayer2 with Apache License 2.0 5 votes vote down vote up
@Override
public void setSurface(Surface surface) {
    if (mMediaPlayer != null) {
        if (surface != null && surface.isValid()) {
            mSurface = surface;
            mMediaPlayer.setSurface(surface);
        }
    }
}
 
Example 18
Source File: AWindow.java    From VCL-Android with Apache License 2.0 5 votes vote down vote up
private void setSurface(Surface surface) {
    if (surface.isValid() && getNativeSurface(mId) == null) {
        mSurface = surface;
        setNativeSurface(mId, mSurface);
        onSurfaceCreated();
    }
}
 
Example 19
Source File: PlayerActivity.java    From android-tv-leanback with Apache License 2.0 5 votes vote down vote up
private void maybeStartPlayback() {
    Log.d(TAG, "maybeStartPlayback");
    Surface surface = surfaceView.getHolder().getSurface();
    if (videoRenderer == null || surface == null || !surface.isValid()) {
        // We're not ready yet.
        return;
    }
    player.sendMessage(videoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE, surface);
    if (autoPlay) {
        player.setPlayWhenReady(true);
        autoPlay = false;
    }
}
 
Example 20
Source File: MediaCodecVideoRenderer.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
public VideoDecoderException(
    Throwable cause, @Nullable MediaCodecInfo codecInfo, @Nullable Surface surface) {
  super(cause, codecInfo);
  surfaceIdentityHashCode = System.identityHashCode(surface);
  isSurfaceValid = surface == null || surface.isValid();
}