2017-05-18 8 views
6

は私が円の内側ExoPlayerViewを表示しようとしていますサークルにExoPlayerを表示する別のExoPlayer(ピクチャーインピクチャー)オーバーレイ:私は角の丸い枠の内側に第二のプレーヤーを入れて試してみました enter image description hereアンドロイド - 、

を( this answerthis one)、プレーヤーは常に親フレームからエスケープしてビデオの完全な長方形を描画します。

GLSurfaceViewを使用するthis solutionが見つかりましたが、このソリューションではExoPlayerではなく従来のMediaPlayerが使用されています。

+0

あなたがExoPlayerでSurfaceViewを使用したいだけのようにリンクされた溶液を使用してGLSurfaceViewを使用してみましたか? (サーフェスリスナーの設定とExoPlayerへのサーフェスの渡し) – etan

+0

他の誰でも実行している人は、SurfaceViewsの代わりにTextureViewsを使用することです。 –

答えて

0

カスタムコンテナを作成する必要があります。これを試してみて、プレーヤーの視点を入れてください。

public class RoundFrameLayout extends FrameLayout { 

private final Path clip = new Path(); 

private int posX; 
private int posY; 
private int radius; 

public RoundFrameLayout(Context context) { 
    this(context,null); 

} 

public RoundFrameLayout(Context context, AttributeSet attrs) { 
    this(context, attrs,0); 
} 

public RoundFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) { 
    super(context, attrs, defStyleAttr); 
    // We can use outlines on 21 and up for anti-aliased clipping. 
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 
     setClipToOutline(true); 
    } 
} 

@Override 
protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight) { 
    posX = Math.round((float) width/2); 
    posY = Math.round((float) height/2); 

    // noinspection NumericCastThatLosesPrecision 
    radius = (int) Math.floor((float) Math.min(width, height)/2); 

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 
     setOutlineProvider(new OutlineProvider(posX, posY, radius)); 
    } else { 
     clip.reset(); 
     clip.addCircle(posX, posY, radius, Direction.CW); 
    } 
} 

@Override 
protected void dispatchDraw(Canvas canvas) { 
    // Not needed on 21 and up since we're clipping to the outline instead. 
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { 
     canvas.clipPath(clip); 
    } 

    super.dispatchDraw(canvas); 
} 

@Override 
public boolean onInterceptTouchEvent(MotionEvent event) { 
    // Don't pass touch events that occur outside of our clip to the children. 
    float distanceX = Math.abs(event.getX() - posX); 
    float distanceY = Math.abs(event.getY() - posY); 
    double distance = Math.hypot(distanceX, distanceY); 

    return distance > radius; 
} 

@TargetApi(Build.VERSION_CODES.LOLLIPOP) 
static class OutlineProvider extends ViewOutlineProvider { 

    final int left; 
    final int top; 
    final int right; 
    final int bottom; 

    OutlineProvider(int posX, int posY, int radius) { 
     left = posX - radius; 
     top = posY - radius; 
     right = posX + radius; 
     bottom = posY + radius; 
    } 

    @Override 
    public void getOutline(View view, Outline outline) { 
     outline.setOval(left, top, right, bottom); 
    } 

} 

}

+0

質問に記載されているように、このソリューションはプレーヤーが丸いコーナーを尊重しないため動作しません親フレームの –