/** * Set the video track. * * @return true on success. */ public boolean setVideoTrack(int index) { /* Don't activate a video track is surfaces are not ready */ if (index == -1 || (mWindow.areViewsAttached() && !mWindow.areSurfacesWaiting())) { return nativeSetVideoTrack(index); } else return false; }
@Override public void setVideoSurface(Surface videoSurface, SurfaceHolder surfaceHolder) { setSurface(ID_VIDEO, videoSurface, surfaceHolder); }
/** * Get the valid Video surface. * * @return can be null if the surface was destroyed. */ @SuppressWarnings("unused") /* used by JNI */ private Surface getVideoSurface() { return getNativeSurface(ID_VIDEO); }
/** * Set a callback in order to receive {@link #nativeOnMouseEvent} and {@link #nativeOnWindowSize} events. * * @param nativeHandle native Handle passed by {@link #nativeOnMouseEvent} and {@link #nativeOnWindowSize}, cannot be NULL * @return true if callback was successfully registered */ @SuppressWarnings("unused") /* used by JNI */ private int registerNative(long nativeHandle) { if (nativeHandle == 0) throw new IllegalArgumentException("nativeHandle is null"); synchronized (mNativeLock) { if (mCallbackNativeHandle != 0) return AWINDOW_REGISTER_ERROR; mCallbackNativeHandle = nativeHandle; if (mMouseAction != -1) nativeOnMouseEvent(mCallbackNativeHandle, mMouseAction, mMouseButton, mMouseX, mMouseY); if (mWindowWidth != -1 && mWindowHeight != -1) nativeOnWindowSize(mCallbackNativeHandle, mWindowWidth, mWindowHeight); int flags = AWINDOW_REGISTER_FLAGS_SUCCESS; if (mOnNewVideoLayoutListener != null) flags |= AWINDOW_REGISTER_FLAGS_HAS_VIDEO_LAYOUT_LISTENER; return flags; } }
@Override @MainThread public void setVideoView(SurfaceView videoSurfaceView) { setView(ID_VIDEO, videoSurfaceView); }
private void setView(int id, TextureView view) { if (!AndroidUtil.isICSOrLater) throw new IllegalArgumentException("TextureView not implemented in this android version"); ensureInitState(); if (view == null) throw new NullPointerException("view is null"); final SurfaceHelper surfaceHelper = mSurfaceHelpers[id]; if (surfaceHelper != null) surfaceHelper.release(); mSurfaceHelpers[id] = new SurfaceHelper(id, view); }
@MainThread private void onSurfaceDestroyed() { detachViews(); }
/** * Play the media * */ public void play() { synchronized (this) { if (!mPlaying) { /* HACK: stop() reset the audio output, so set it again before first play. */ if (mAudioReset) { if (mAudioOutput != null) nativeSetAudioOutput(mAudioOutput); if (mAudioOutputDevice != null) nativeSetAudioOutputDevice(mAudioOutputDevice); mAudioReset = false; } mPlayRequested = true; if (mWindow.areSurfacesWaiting()) return; } mPlaying = true; } nativePlay(); }
@Override public void setWindowSize(int width, int height) { synchronized (mNativeLock) { if (mCallbackNativeHandle != 0 && (mWindowWidth != width || mWindowHeight != height)) nativeOnWindowSize(mCallbackNativeHandle, width, height); mWindowWidth = width; mWindowHeight = height; } }
@Override public void sendMouseEvent(int action, int button, int x, int y) { synchronized (mNativeLock) { if (mCallbackNativeHandle != 0 && (mMouseAction != action || mMouseButton != button || mMouseX != x || mMouseY != y)) nativeOnMouseEvent(mCallbackNativeHandle, action, button, x, y); mMouseAction = action; mMouseButton = button; mMouseX = x; mMouseY = y; } }
@Override @MainThread public void attachViews() { attachViews(null); }
@Override @MainThread public void setVideoView(TextureView videoTextureView) { setView(ID_VIDEO, videoTextureView); }
private void setView(int id, SurfaceView view) { ensureInitState(); if (view == null) throw new NullPointerException("view is null"); final SurfaceHelper surfaceHelper = mSurfaceHelpers[id]; if (surfaceHelper != null) surfaceHelper.release(); mSurfaceHelpers[id] = new SurfaceHelper(id, view); }
@MainThread private void onSurfaceDestroyed() { detachViews(); }
/** * Play the media * */ public void play() { synchronized (this) { if (!mPlaying) { /* HACK: stop() reset the audio output, so set it again before first play. */ if (mAudioReset) { if (mAudioOutput != null) nativeSetAudioOutput(mAudioOutput); if (mAudioOutputDevice != null) nativeSetAudioOutputDevice(mAudioOutputDevice); mAudioReset = false; } mPlayRequested = true; if (mWindow.areSurfacesWaiting()) return; } mPlaying = true; } nativePlay(); }
/** * Set a callback in order to receive {@link #nativeOnMouseEvent} and {@link #nativeOnWindowSize} events. * * @param nativeHandle native Handle passed by {@link #nativeOnMouseEvent} and {@link #nativeOnWindowSize}, cannot be NULL * @return true if callback was successfully registered */ @SuppressWarnings("unused") /* used by JNI */ private int registerNative(long nativeHandle) { if (nativeHandle == 0) throw new IllegalArgumentException("nativeHandle is null"); synchronized (mNativeLock) { if (mCallbackNativeHandle != 0) return AWINDOW_REGISTER_ERROR; mCallbackNativeHandle = nativeHandle; if (mMouseAction != -1) nativeOnMouseEvent(mCallbackNativeHandle, mMouseAction, mMouseButton, mMouseX, mMouseY); if (mWindowWidth != -1 && mWindowHeight != -1) nativeOnWindowSize(mCallbackNativeHandle, mWindowWidth, mWindowHeight); int flags = AWINDOW_REGISTER_FLAGS_SUCCESS; if (mOnNewVideoLayoutListener != null) flags |= AWINDOW_REGISTER_FLAGS_HAS_VIDEO_LAYOUT_LISTENER; return flags; } }
@Override public void setWindowSize(int width, int height) { synchronized (mNativeLock) { if (mCallbackNativeHandle != 0 && (mWindowWidth != width || mWindowHeight != height)) nativeOnWindowSize(mCallbackNativeHandle, width, height); mWindowWidth = width; mWindowHeight = height; } }
@Override public void sendMouseEvent(int action, int button, int x, int y) { synchronized (mNativeLock) { if (mCallbackNativeHandle != 0 && (mMouseAction != action || mMouseButton != button || mMouseX != x || mMouseY != y)) nativeOnMouseEvent(mCallbackNativeHandle, action, button, x, y); mMouseAction = action; mMouseButton = button; mMouseX = x; mMouseY = y; } }
@Override @MainThread public void attachViews() { attachViews(null); }
@Override @MainThread public void setSubtitlesView(SurfaceView subtitlesSurfaceView) { setView(ID_SUBTITLES, subtitlesSurfaceView); }