Using Android's TextureView to Display Video Mirrored
来源:互联网 发布:尤克里里推荐知乎 编辑:程序博客网 时间:2024/06/16 04:25
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;@Overrideprotected 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);}@Overridepublic 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();}}@Overridepublic boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture) {return false;}@Overridepublic void onSurfaceTextureSizeChanged(SurfaceTexture surfaceTexture, int width, int height) {}@Overridepublic void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) {}}
0 0
- Using Android's TextureView to Display Video Mirrored
- Use xawtv to display vivi video
- Using Gstreamer to Play Video Files
- how to display '&' in subject using mailto?
- Using UIWebView to display select document types
- using android toolbox's r to access phys addr
- How to do video broadcast using multicast group?
- Add Subtitle (srt) to Video by using Ffmpeg
- mit 6.00 introduction to computer science using Python video note
- Using opencv to process the video stream from camera
- Using .NET Databinding to Display Ink from a Database
- How to display Chinese characters exactly when using Tomcat.
- basic steps for using classes to display alv report
- Using a modal .NET dialog to display AutoCAD object properties
- Using a modeless .NET dialog to display AutoCAD object properties
- How to display XML in a JTree using JDOM
- Android之TextureView浅析
- android TextureView 浅析
- JavaScript利用URL向后台传入中文参数乱码问题解决之道!
- 第四章知识导图
- 注册表修改PSD关联photoshop
- 利用uboot启动远程Kernel(TFTp)
- Chrome 程序启动
- Using Android's TextureView to Display Video Mirrored
- android 中的4种activity启动模式(launchMode)
- iOS开发学习之#提醒处理#(1)响应提醒视图
- 备忘录模式
- 友盟自定义事件的使用方法
- 嵌入式高手谈嵌入式
- iOS UItableView+UINavigationController实现单元格的删除
- Android DialogFragment fullscreen 解决方法
- 大学在校生4000元起家 大三时身家30万