Using Android's TextureView to Display Video Mirrored

http://adevelopers-blog.blogspot.sg/2014/02/using-androids-textureview-to-display.html

Android's VideoView can only play videos straight and not mirrored.
If you want your app to play a video mirrored (for instance if the video was recorded using a front camera), you will need to use a TextureView, which can be easily mirrored by specifyingandroid:scaleX=-1 in the XML file, or textureView.setScaleX(-1) in the code.

Here is a code sample for playing video using TextureView, with the option of displaying the video mirrored:

1234567891011121314151617181920212223242526272829303132
         
         
public class SampleActivity implements SurfaceTextureListener {
boolean isMirrored = true;
@Override
protected void onCreate( Bundle savedInstanceState) {
super .onCreate(savedInstanceState);
setContentView( R .layout .activity_sample);
TextureView textureView = ( TextureView)findViewById( R .id .myTextureView);
textureView .setSurfaceTextureListener( this);
textureView .setScaleX(isMirrored ? - 1 : 1);
}
 
@Override
public void onSurfaceTextureAvailable( SurfaceTexture surface, int width, int height) {
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer .setSurface( new Surface(surface));
try {
mediaPlayer .setDataSource( "my_video_file.mp4");
mediaPlayer .prepare();
mediaPlayer .start();
} catch ( Exception e) {
e .printStackTrace();
}
}
@Override
public boolean onSurfaceTextureDestroyed( SurfaceTexture surfaceTexture) { return false;}
@Override
public void onSurfaceTextureSizeChanged( SurfaceTexture surfaceTexture, int width, int height) {}
@Override
public void onSurfaceTextureUpdated( SurfaceTexture surfaceTexture) {}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值