2017-05-18 17 views
6

ben bir daire içinde bir ExoPlayerView görüntülemek için çalışıyorum bir daire içinde ExoPlayer gösteriliyor başka ExoPlayer (resimde resim) yayılmasıyla: Ben köşeleri yuvarlatılmış bir çerçevenin içine 2 oyuncu koyarak denedim enter image description hereAndroid -

(hem this answer ve this one) ama oyuncu her zaman üst çerçeve kaçmak ve videonun tam dikdörtgen çekecektir.

Bir GLSurfaceView kullanır this solution bulundu, ancak bu çözüm klasik MediaPlayer olup ExoPlayer kullanır.

+0

Eğer bağlantılı çözüm kullanarak ve ExoPlayer ile SurfaceView kullanmak atar gibi GLSurfaceView kullanmayı denediniz mi? Oyuncunun yuvarlatılmış köşeler saygı duymayan olarak bu işe çalışan – etan

+0

Başkasının (yüzey dinleyici kurma ve ExoPlayer yüzeye geçen), çözüm söz konusu belirtildiği gibi yerine SurfaceViews –

cevap

0

Bunun için özel bir kapsayıcı oluşturmak gerekir. Bunu dene ve oyuncu görünümünü koy.

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

ait TextureViews kullanmaktır, bu çözüm işe yaramaz ana çerçevenin –