use of org.videolan.libvlc.IVLCVout in project vlc-android by videolan.
the class VideoPlayerActivity method changeSurfaceLayout.
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private void changeSurfaceLayout() {
int sw;
int sh;
// get screen size
if (mDisplayManager.isPrimary()) {
sw = getWindow().getDecorView().getWidth();
sh = getWindow().getDecorView().getHeight();
} else if (mDisplayManager.getPresentation() != null) {
sw = mDisplayManager.getPresentation().getWindow().getDecorView().getWidth();
sh = mDisplayManager.getPresentation().getWindow().getDecorView().getHeight();
} else
return;
// sanity check
if (sw * sh == 0) {
Log.e(TAG, "Invalid surface size");
return;
}
if (mService != null) {
final IVLCVout vlcVout = mService.getVLCVout();
vlcVout.setWindowSize(sw, sh);
}
SurfaceView surface;
SurfaceView subtitlesSurface;
FrameLayout surfaceFrame;
if (mDisplayManager.isPrimary()) {
surface = mSurfaceView;
subtitlesSurface = mSubtitlesSurfaceView;
surfaceFrame = mSurfaceFrame;
} else if (mDisplayManager.getDisplayType() == DisplayManager.DisplayType.PRESENTATION) {
surface = mDisplayManager.getPresentation().getSurfaceView();
subtitlesSurface = mDisplayManager.getPresentation().getSubtitlesSurfaceView();
surfaceFrame = mDisplayManager.getPresentation().getSurfaceFrame();
} else
return;
LayoutParams lp = surface.getLayoutParams();
if (mVideoWidth * mVideoHeight == 0 || isInPictureInPictureMode()) {
/* Case of OpenGL vouts: handles the placement of the video using MediaPlayer API */
lp.width = LayoutParams.MATCH_PARENT;
lp.height = LayoutParams.MATCH_PARENT;
surface.setLayoutParams(lp);
lp = surfaceFrame.getLayoutParams();
lp.width = LayoutParams.MATCH_PARENT;
lp.height = LayoutParams.MATCH_PARENT;
surfaceFrame.setLayoutParams(lp);
if (mService != null && mVideoWidth * mVideoHeight == 0)
changeMediaPlayerLayout(sw, sh);
return;
}
if (mService != null && lp.width == lp.height && lp.width == LayoutParams.MATCH_PARENT) {
/* We handle the placement of the video using Android View LayoutParams */
mService.setVideoAspectRatio(null);
mService.setVideoScale(0);
}
double dw = sw, dh = sh;
boolean isPortrait;
// getWindow().getDecorView() doesn't always take orientation into account, we have to correct the values
isPortrait = mDisplayManager.isPrimary() && mCurrentScreenOrientation == Configuration.ORIENTATION_PORTRAIT;
if (sw > sh && isPortrait || sw < sh && !isPortrait) {
dw = sh;
dh = sw;
}
// compute the aspect ratio
double ar, vw;
if (mSarDen == mSarNum) {
/* No indication about the density, assuming 1:1 */
vw = mVideoVisibleWidth;
ar = (double) mVideoVisibleWidth / (double) mVideoVisibleHeight;
} else {
/* Use the specified aspect ratio */
vw = mVideoVisibleWidth * (double) mSarNum / mSarDen;
ar = vw / mVideoVisibleHeight;
}
// compute the display aspect ratio
double dar = dw / dh;
switch(mCurrentSize) {
case SURFACE_BEST_FIT:
if (dar < ar)
dh = dw / ar;
else
dw = dh * ar;
break;
case SURFACE_FIT_SCREEN:
if (dar >= ar)
dh = dw / ar;
else
/* horizontal */
dw = dh * ar;
/* vertical */
break;
case SURFACE_FILL:
break;
case SURFACE_16_9:
ar = 16.0 / 9.0;
if (dar < ar)
dh = dw / ar;
else
dw = dh * ar;
break;
case SURFACE_4_3:
ar = 4.0 / 3.0;
if (dar < ar)
dh = dw / ar;
else
dw = dh * ar;
break;
case SURFACE_ORIGINAL:
dh = mVideoVisibleHeight;
dw = vw;
break;
}
// set display size
lp.width = (int) Math.ceil(dw * mVideoWidth / mVideoVisibleWidth);
lp.height = (int) Math.ceil(dh * mVideoHeight / mVideoVisibleHeight);
surface.setLayoutParams(lp);
subtitlesSurface.setLayoutParams(lp);
// set frame size (crop if necessary)
lp = surfaceFrame.getLayoutParams();
lp.width = (int) Math.floor(dw);
lp.height = (int) Math.floor(dh);
surfaceFrame.setLayoutParams(lp);
surface.invalidate();
subtitlesSurface.invalidate();
}
use of org.videolan.libvlc.IVLCVout in project vlc-android by videolan.
the class VideoPlayerActivity method handleVout.
private void handleVout(int voutCount) {
mHandler.removeCallbacks(mSwitchAudioRunnable);
final IVLCVout vlcVout = mService.getVLCVout();
if (vlcVout.areViewsAttached() && voutCount == 0) {
mHandler.postDelayed(mSwitchAudioRunnable, 4000);
}
}
use of org.videolan.libvlc.IVLCVout in project vlc-android by videolan.
the class VideoPlayerActivity method sendMouseEvent.
private void sendMouseEvent(int action, int x, int y) {
if (mService == null)
return;
final IVLCVout vlcVout = mService.getVLCVout();
vlcVout.sendMouseEvent(action, 0, x, y);
}
use of org.videolan.libvlc.IVLCVout in project vlc-android by GeoffreyMetais.
the class VideoPlayerActivity method stopPlayback.
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void stopPlayback() {
if (!mPlaybackStarted)
return;
if (mDisplayManager.isOnRenderer() && !isFinishing()) {
mPlaybackStarted = false;
return;
}
mWasPaused = !mService.isPlaying();
if (!isFinishing()) {
mCurrentAudioTrack = mService.getAudioTrack();
mCurrentSpuTrack = mService.getSpuTrack();
}
if (mMute)
mute(false);
mPlaybackStarted = false;
mService.setVideoTrackEnabled(false);
mService.removeCallback(this);
mHandler.removeCallbacksAndMessages(null);
final IVLCVout vlcVout = mService.getVLCVout();
vlcVout.removeCallback(this);
vlcVout.detachViews();
if (mService.hasMedia() && mSwitchingView) {
if (BuildConfig.DEBUG)
Log.d(TAG, "mLocation = \"" + mUri + "\"");
if (mSwitchToPopup)
mService.switchToPopup(mService.getCurrentMediaPosition());
else {
mService.getCurrentMediaWrapper().addFlags(MediaWrapper.MEDIA_FORCE_AUDIO);
mService.showWithoutParse(mService.getCurrentMediaPosition());
}
return;
}
if (mService.isSeekable()) {
mSavedTime = getTime();
long length = mService.getLength();
// remove saved position if in the last 5 seconds
if (length - mSavedTime < 5000)
mSavedTime = 0;
else
// go back 2 seconds, to compensate loading time
mSavedTime -= 2000;
}
mSavedRate = mService.getRate();
mRateHasChanged = mSavedRate != 1.0f;
mService.setRate(1.0f, false);
mService.stop();
}
use of org.videolan.libvlc.IVLCVout in project butter-android by butterproject.
the class VlcPlayer method attachToSurface.
public void attachToSurface(SurfaceView videoSurface, SurfaceView subsSurface) {
final IVLCVout vlcVout = mediaPlayer.getVLCVout();
if (!vlcVout.areViewsAttached()) {
vlcVout.setVideoView(videoSurface);
vlcVout.setSubtitlesView(subsSurface);
vlcVout.addCallback(this);
vlcVout.attachViews(this);
}
}
Aggregations