0

I am using TextureView to show my live stream from the camera. I wrote a function that switch between front and back camera through flip animation. When I flip The Textureview through animation from 90 to 180 degree. It show the live stream right to left instead of left to right. This behavior is understandable because left corner become right on flip animation. How can I change the live stream after animation. I have tried a lot but could not find any solution. Any Suggestion or solution to solve this problem please.

user1154390
  • 2,331
  • 3
  • 25
  • 32
  • As a suggestion, you can flip your view to 360 degrees instead of 180 degrees. That way you will achieve your animation and your camera wouldn't be horizontally flipped. – Salman Khakwani Feb 24 '15 at 12:31
  • Thanks @Salman Muhammad Ayub but 360 doesn't look nice. It spins the whole view. – user1154390 Feb 24 '15 at 12:36

1 Answers1

1

You can apply a transformation matrix on your texture view to flip your camera horizontally.

You need to apply this transformation in onSurfaceTextureAvailable(..) callback:

public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int width, int height) 
{
//If you are in portrait mode.
//mCamera.setDisplayOrientation(90);

//If you want to flip only front camera.
if(YOUR_FRONT_CAMERA_FLAG)
{
    Matrix matrix = new Matrix();
    matrix.setScale(-1, 1);
    matrix.postTranslate(width, 0);
    mTextureView.setTransform(matrix);
}
}

I hope this solves your problem.

Salman Khakwani
  • 6,684
  • 7
  • 33
  • 58
  • I have already tried this solution but it did not work. front camera work fine this problem occurs on back camera. – user1154390 Feb 24 '15 at 12:56
  • are you applying transformation without any flags , i mean are you applying transformation on both back and front cameras ? – Salman Khakwani Feb 24 '15 at 12:58
  • When I load the textureview it picks up the front camera so i don't need the setTransform. On click it flip and pick up the back camera. I used transform only on the back camera. – user1154390 Feb 24 '15 at 13:06
  • bingo, here we have your problem spotted. You don't need to apply transform there. try removing it and come back to me :) – Salman Khakwani Feb 24 '15 at 13:08
  • And you can also post your `onSurfaceTextureAvailable(..)` code along with your question, so that it will be easy for us to spot the problem. – Salman Khakwani Feb 24 '15 at 13:10
  • Thanks @ Salman Muhammad Ayub for your comments. I can not paste the code because code spreads on three classes. I have changed the animation with 90 to 0 degree along y axis to solve the issue right now because shortage of time. I'll dig into later – user1154390 Feb 25 '15 at 11:21
  • @Salman, this worked for me,now i want to revrese it back.how to do it ? – JosephM Aug 30 '16 at 09:19