本文介绍了调整/缩放下来YouTubePlayerFragment在播放视频时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图复制视频最小化的YouTube应用,如图。为了实现这一点,我已经使用库尝试。当我跑的样本,我注意到,该视频不结垢​​,但是当在播放过程中最小化,而作物。当视频停止(未暂停)和显示缩略图时,视图比例为它应该。我读上YouTubePlayerView与SurfaceView实现的另一个问题。我也看了在SurfaceView从普通视图的行为,因为它是如何在拳屏幕中的孔不同的文档。我相信,因为YoutubePlayerView不基于SurfaceView的,它不结垢正常。我如何缩放视频玩YoutubePlayerView内适当地在播放过程中其父布局的大小相匹配?

I am trying to replicate the video minimization in the Youtube app as shown here. In order to achieve this, I've tried using the Draggable Panel library. When I ran the sample, I noticed that the video does not scale but rather crops when minimized during playback. When the video is stopped (not paused) and displaying a thumbnail, the view scales as its supposed to. I read on another question that YouTubePlayerView is implemented with a SurfaceView. I also read in the docs that SurfaceView behaves differently from a normal view because of how it punches a hole in the screen. I believe because YoutubePlayerView is based off of SurfaceView ,it's not scaling properly. How do I scale the video playing within a YoutubePlayerView properly to match the size of its parent layout during playback?

推荐答案

在我与YouTubePlayerView和YouTubePlayerFragment的工作经验,我发现,Nineoldandroids或ViewPropertyAnimator缩放不能正常工作。为了调节播放视频的大小,你必须以编程方式设置布局参数的高度和宽度。在DraggablePanel库有两个类来改变顶视图的大小。默认值是ScaleTransformer它确实为视频播放过程中,因为它裁剪播放视频的一部分了看法不行,另一种是ResizeTransformer。 ResizeTransformer并不像ScaleTransformer一样光滑,但它的工作原理有点。与ResizeTransformer的问题是,YouTubePlayerView的布局有时而底部视图下的剪辑被拖动。然后播放停止,因为它检测到一个视图重叠它。我做了妥协,去掉DraggablePanel谱写最大化和最小化YouTubePlayerView的容器的方法。

In my experience with working with YouTubePlayerView and YouTubePlayerFragment, I found that scaling with Nineoldandroids or ViewPropertyAnimator does not work properly. In order to adjust the size of the playing video you must set the height and width of the layout parameters programmatically. In the DraggablePanel library there are two classes to change the size of the top view. The default is ScaleTransformer which doesn't work for videos during playback because it crops part of the playing video out of the view, the other is ResizeTransformer. ResizeTransformer isn't as smooth as the ScaleTransformer but it works somewhat. The problem with ResizeTransformer is that the YouTubePlayerView's layout sometimes clips under the bottom view while being dragged. Playback then stops because it detects a view overlapped it. I made the compromise to strip out DraggablePanel and write a maximize and minimize method for YouTubePlayerView's container.

public void minimize() {
    RelativeLayout.LayoutParams playerParams =
            (RelativeLayout.LayoutParams) playerView.getLayoutParams();
    playerParams.width = getResources().getDimensionPixelSize(R.dimen.player_minimized_width);
    playerParams.height = getResources().getDimensionPixelSize(R.dimen.player_minimized_height);
    FrameLayout container = (FrameLayout)playerView.getParent().getParent();
    RelativeLayout.LayoutParams containerParams = (RelativeLayout.LayoutParams)container.getLayoutParams();
    containerParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    containerParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    containerParams.bottomMargin = getResources().getDimensionPixelSize(R.dimen.player_minimized_margin);
    containerParams.rightMargin = getResources().getDimensionPixelSize(R.dimen.player_minimized_margin);
    playerView.requestLayout();
    container.requestLayout();
    isMinimized = true;
}

public void maximize() {
    RelativeLayout.LayoutParams playerParams =
            (RelativeLayout.LayoutParams) playerView.getLayoutParams();
    playerParams.width = RelativeLayout.LayoutParams.MATCH_PARENT;
    playerParams.height = getResources().getDimensionPixelSize(R.dimen.player_height);
    FrameLayout container = (FrameLayout)playerView.getParent().getParent();
    RelativeLayout.LayoutParams containerParams = (RelativeLayout.LayoutParams)container.getLayoutParams();
    containerParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM,0);
    containerParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT,0);
    containerParams.bottomMargin = 0;
    containerParams.rightMargin = 0;
    playerView.requestLayout();
    container.requestLayout();
    isMinimized = false;
}

这篇关于调整/缩放下来YouTubePlayerFragment在播放视频时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-04 00:21