我的问题有2部分。
答案 0 :(得分:2)
对于这种视频操作,你绝对应该看看TextureView。
此视图可用于通过MediaPlayer呈现视频,您可以对其应用任何转换。
以下是如何使用它播放视频的简单示例(使用哑缩放动画):
public class TestActivity extends Activity implements SurfaceTextureListener {
private static final String VIDEO_URL = "http://www.808.dk/pics/video/gizmo.mp4";
private MediaPlayer player;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
player = MediaPlayer.create(this, Uri.parse(VIDEO_URL));
setContentView(R.layout.main);
TextureView videoView = (TextureView) findViewById(R.id.video);
videoView.setSurfaceTextureListener(this);
// Scaling
Animation scaling = new ScaleAnimation(0.2f, 1.0f, 0.2f, 1.0f);
scaling.setDuration(2000);
videoView.startAnimation(scaling);
}
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
player.setSurface(new Surface(surface));
player.start();
}
@Override
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) { }
@Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) { return false; }
@Override
public void onSurfaceTextureUpdated(SurfaceTexture surface) { }
}
使用以下main.xml:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextureView
android:id="@+id/video"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
请注意,此TextureView仅适用于API级别&gt; = 14。