在Android的TextureView的文档,它说,你可以使用一个TextureView播放视频:http://developer.android.com/reference/android/view/TextureView.html
In the documentation of Android TextureView it says that you can use a TextureView to play video: http://developer.android.com/reference/android/view/TextureView.html
不过,我似乎无法找到如何做到这一点的任何例子。有谁知道?
But I cant seem to find any example of how to do this. Does anyone know?
我需要使用textureView,因为我想动画视频。我想在名为.3gp / .MP4格式播放视频时,从摄像机不是视频:)
I need to use a textureView because I want to animate the video. I want to play a video in .3gp/.mp4 format, not video from the Camera :)
任何帮助将是AP preciated ..
Any help would be appreciated..
更新:
解决方案张贴作为一个社会维基答案
Solution is posted as a community wiki answer
下面是你如何能做到这一点: (对这个问题笔者的解决方案,他贴在问题的更新)
Here is how you can do it: (solution by the question author, that he posted as an update in the question)
Public class MediaPlayerDemo_Video extends Activity implements TextureView.SurfaceTextureListener {
private MediaPlayer mMediaPlayer;
private TextureView mPreview;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
mPreview = (TextureView) findViewById(R.id.surface);
mPreview.setSurfaceTextureListener(this);
extras = getIntent().getExtras();
setContentView(mPreview);
}
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
Surface s = new Surface(surface);
try {
mMediaPlayer= new MediaPlayer();
mMediaPlayer.setDataSource("http://daily3gp.com/vids/747.3gp");
mMediaPlayer.setSurface(s);
mMediaPlayer.prepare();
mMediaPlayer.setOnBufferingUpdateListener(this);
mMediaPlayer.setOnCompletionListener(this);
mMediaPlayer.setOnPreparedListener(this);
mMediaPlayer.setOnVideoSizeChangedListener(this);
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
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();
}
}
和动画它的作品真的很好。
And animating it works really well.