我尝试对使用纹理视图渲染的视频进行动画处理,动画效果很好,但是当我将纹理缩放到不同的大小时,媒体播放器不会缩放以适应纹理的大小,视频始终在全屏播放背景,当我缩放纹理时我只能看到视频的一部分
我的代码在某些运行 android 4.0 的 Android 设备上运行良好,但在具有更高版本 android 的设备上不起作用。这是我的动画代码,请告诉我问题出在哪里..
public class MainActivity extends Activity implements TextureView.SurfaceTextureListener{
AnimationSet animset;
TextureView myTexture;
MediaPlayer mMediaPlayer;
Surface s;
int height;
static final String LogFileName = "Log";
int width;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
myTexture = new TextureView(this);
myTexture.setSurfaceTextureListener(this);
setContentView(myTexture);
}
@Override
public void onSurfaceTextureAvailable(SurfaceTexture arg0, int arg1,
int arg2) {
String mediaStorageDir = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DOWNLOADS).getAbsolutePath();
s = new Surface(arg0);
try {
mMediaPlayer= new MediaPlayer();
mMediaPlayer.setSurface(s);
mMediaPlayer.setDataSource(mediaStorageDir+"/AirIndia.mp4");
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mMediaPlayer.prepareAsync();
mMediaPlayer.setLooping(true);
mMediaPlayer.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mMediaPlayer.start();
}
});
// to animate the texture
animset =new AnimationSet(true);
animset.addAnimation(scaling);
animset.addAnimation(translate);
animset.setStartOffset(20000);
Animation fulscaling = new ScaleAnimation(1.0f, 1.3333f, 1.0f, 1.3333f);
TranslateAnimation fulltranslate = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0.0f,Animation.RELATIVE_TO_SELF, -0.3333f, 0, 0.0f, 0, 0.0f);
fulltranslate.setStartOffset(10000);
animset.setDuration(1000);
animset.setFillAfter(true);
animset.setFillEnabled(true);
fulscaling.setStartOffset(10000);
animset.addAnimation(fulscaling);
animset.addAnimation(fulltranslate);
myTexture.setAnimation(animset);
animset.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationEnd(Animation arg0) {
myTexture.startAnimation(animset);
}
@Override
public void onAnimationRepeat(Animation arg0) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationStart(Animation arg0) {
// TODO Auto-generated method stub
}
});
} catch (IllegalArgumentException e) {
showToast(e.getMessage());
e.printStackTrace();
} catch (SecurityException e) {
showToast(e.getMessage());
e.printStackTrace();
} catch (IllegalStateException e) {
showToast(e.getMessage());
e.printStackTrace();
} catch (IOException e) {
showToast(e.getMessage());
e.printStackTrace();
}
}
如果要缩放TextureView的内容,请使用
setTransform()
。 有关示例,请参阅 Grafika 的 PlayMovieActivity类中的
adjustAspectRatio()
,该类会更改 TextureView 内容的大小以匹配正在播放的视频的宽高比。
我很抱歉,但我现在遇到了这个麻烦=(你怎么能解决这个问题?