0

我正在尝试为使用纹理视图渲染的视频制作动画,动画效果很好,但是当我将纹理缩放到不同的大小时,媒体播放器不会缩放以适应纹理的大小,视频总是在后台全屏播放当我缩放纹理时,我只能看到部分视频,
我的代码在一些运行 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();
} 

}

4

1 回答 1

5

如果要缩放 TextureView 的内容,请使用setTransform(). 例如,请参阅adjustAspectRatio()Grafika 的PlayMovieActivity类,它会更改 TextureView 内容的大小以匹配正在播放的视频的纵横比。

于 2014-11-27T16:42:55.093 回答