Two videos layers with an moving hole

  • Replies:0
Or Sarfati
  • Forum posts: 1

Nov 15, 2015, 11:23:24 PM via Website

Hellow all. after two dayes of tryings I'll try my luck here:

I'm trying to make an app with a moving magnifier on a video background. The video should be static while the magnifier moves freely on the screen and magnify the selected position.

Then tried to use SurfaceView or TextureView with MediaPlayer to preview the video as background and paint on it - until now with no success.

The code for now:

    mtTextureView = (TextureView) findViewById(R.id.textureView);
    mtTextureView.setSurfaceTextureListener(new TextureView.SurfaceTextureListener({
    @Override
    public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
        Surface s = new Surface(surface);
        try {
            mMediaPlayer = new MediaPlayer();
            mMediaPlayer.setDataSource(uri.toString());
            mMediaPlayer.setSurface(s);
            mMediaPlayer.prepare();
            mMediaPlayer.start();
        } catch (IllegalArgumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SecurityException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalStateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    @Override
    public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int             width, int height) {

    }

    @Override
    public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
        return false;
    }

    @Override
    public void onSurfaceTextureUpdated(SurfaceTexture surface) {

    }

});
mtTextureView.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        Canvas canvas = mtTextureView.lockCanvas();
        Paint paint = new Paint();
        paint.setColor(Color.GREEN);
        paint.setStyle(Paint.Style.STROKE);
        float x = 50;
        float y = 50;
        float radius = 20;
        canvas.drawCircle(x, y, radius, paint);
        mtTextureView.unlockCanvasAndPost(canvas);
        return false;
    }
});

Please help. actually i do not know where to go next.

Suggestions to butter ways to do it will be most welcome Thanks again!
Or

Reply