为什么我的视频亘古不适合纹理的大小,因为我改变纹理的大小 [英] why my video doesnot fit the size of the texture as i change the size of the texture

查看:310
本文介绍了为什么我的视频亘古不适合纹理的大小,因为我改变纹理的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

荫试图动画视频渲染使用纹理视图,动画工作正常,但是当我缩放纹理大小不同的媒体播放器不能扩展,以适应纹理的大小,视频总是播放全屏在后台,我只可以看到视频的一部分,当我缩放质感结果
  我的code正常工作运行Android 4.0的一些Android设备,但是,与后来的Andr​​oid版本的设备不工作。我的继承人code为动画请你告诉我问题出在哪里。

Iam trying to animate a video rendered using texture view, the animation works fine , but when i scale the texture to a different size the media player does not scale to fit the size of the texture,the video is always playing full screen in the background and i can only see part of the video when i scale the texture
my code works fine on some android devices running android 4.0 but does not work on devices with later versions of android . heres my code for the animation kindly tell me where the problem is ..

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()。举一个例子,看看 adjustAspectRatio()在Grafika的的 PlayMovieActivity 的类,这改变的TextureView内容的大小以匹配视频的纵横比正在播放

If you want to scale the TextureView's contents, use setTransform(). For an example, see adjustAspectRatio() in Grafika's PlayMovieActivity class, which changes the size of the TextureView contents to match the aspect ratio of the video being played.

这篇关于为什么我的视频亘古不适合纹理的大小,因为我改变纹理的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆