You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android Studio 3集成Vuforia时如何实现圆形视频播放?

Hey there! Let's figure out how to make your Vuforia video play in a circular format with Android Studio 3. I've worked through similar AR rendering tweaks before, so here are two reliable approaches you can try:

This method handles the clipping directly in the AR rendering pipeline, which integrates seamlessly with Vuforia's target tracking:

  • First, locate the default shaders used by Vuforia in your project (usually in app/src/main/assets/shaders or the rendering-related directory). Make a copy of the fragment shader that's used for video playback.
  • Update the copied fragment shader to add circular clipping logic. Here's a sample implementation:
    precision mediump float;
    uniform sampler2D texSampler;
    varying vec2 vTexCoord;
    
    void main() {
        // Calculate distance from current pixel to texture center
        vec2 textureCenter = vec2(0.5, 0.5);
        float pixelDistance = distance(vTexCoord, textureCenter);
        
        // Discard pixels outside the circular area (radius set to half the texture size)
        if (pixelDistance > 0.5) {
            discard;
        }
        
        // Sample and output the video texture color
        gl_FragColor = texture2D(texSampler, vTexCoord);
    }
    
  • In your Vuforia rendering code (like the VideoPlayerRenderer or similar class), swap out the default shader program with this custom one when initializing the video texture.
  • Pro tip: If you want adjustable circle sizes, turn the radius into a uniform variable so you can pass values dynamically from your Kotlin/Java code.

Approach 2: Clip the Android View Layer (Quick & Simple)

If you'd rather avoid shader code, you can use Android's view clipping to turn your video view into a circle:

  • Create a custom CircularVideoView that extends TextureView (Vuforia typically uses TextureView for video output):
    class CircularVideoView(context: Context, attrs: AttributeSet?) : TextureView(context, attrs) {
        private val clipPath = Path()
    
        override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
            super.onSizeChanged(w, h, oldw, oldh)
            // Create a circular path centered in the view
            val circleRadius = min(w, h) / 2f
            clipPath.addCircle(w / 2f, h / 2f, circleRadius, Path.Direction.CW)
        }
    
        override fun dispatchDraw(canvas: Canvas) {
            canvas.clipPath(clipPath)
            super.dispatchDraw(canvas)
        }
    }
    
  • Replace the original TextureView in your layout XML with this custom CircularVideoView.
  • Note: This method clips at the Android view level, so make sure your AR content renders correctly beneath or above this view (adjust view elevation if needed) to avoid overlay issues.

Quick Notes

  • If you're using Vuforia's official VideoPlayback sample, go with the shader approach—it aligns perfectly with the sample's existing rendering pipeline.
  • Keep your video aspect ratio in mind! A 16:9 video will have parts cut off in a circle; adjust the shader's center or radius if you want to tweak which parts of the video are visible.

内容的提问来源于stack exchange,提问作者Shadab Khan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 11:10:39