アニメーション付きのビデオビューを使用しています(video.setAnimation(slideinRight);)トランジションでは、ビデオではなく、ビデオビューのレイアウトのみがアニメーション化されていることを除いて、すべて正常に機能します。翻訳アニメーションが発生すると、ボックスが移動してビデオをマスクしますが、ビデオが一緒に移動することはありません。私は今何をすべきか途方に暮れています。
3 に答える
現在、VideoViewにアニメーションを配置しようとしています。
Androidのソースコードを見ると、VideoViewは基本的にSurfaceViewであり、 MediaPlayerと組み合わされており、プレーヤーのステートマシンの基本的な管理が行われています。
実際、実際の「描画」作業は、mediaPlayerのネイティブメソッド(Androidデバイスでの実際のプレーヤーエンジンの実装)によって処理されるようです。
さまざまなデバイスでアニメーションをテストしたところ、VideoViewの基本的なビデオプレーヤーの動作/実装は、さまざまなAndroidデバイス間で同じではないことがわかりました。
- 一部のデバイスは、プレーヤーのビューアニメーションを正しく処理します
- 他の人はしないでください、そしてただぼやけ、黒い画面、またはバグのある表示を表示してください...
その上、VideoViewはメモリに直接書き込まれているように見えるため、「回避策」(不透明なビューを前面に配置し、そのビューにアニメーションを設定するなど)は機能しないようです。
これについて他の人にフィードバックをいただければ幸いです:)
これにかなり遅れて答えて申し訳ありませんが、それだけの価値があります。また、「スライド」アニメーションのみを使用する場合。ビデオビューをレイアウトに配置し、レイアウトをアニメーション化してみてください。
コードで設定する方法は次のとおりです。
AbsoluteLayout Animationlayout = (AbsoluteLayout)findViewById(R.string.frontlayout);
VideoView pvv = new VideoView(getApplicationContext());
pvv.getHolder().addCallback(this);
Animationlayout.addView(pvv);
// load video data in pvv.
次に、ビデオビューをアニメーション化してスライドさせたい場所。
Animationlayout.animate().xBy(25).setDuration(500).setInterpolator(new BounceInterpolator());
これは3.1アニメーションシステムであることに注意してください。
従来の2.1のアニメーション方法がこのように機能するかどうかはわかりませんが、同じように機能するはずです。
レイアウトを回転/スケーリングするようなものは機能しません。レイアウトをパンしてフェードアウトすることだけが機能するようです。
TextureViewを使用するだけです:
TextureViewの詳細については、こちらをご覧ください。
TextureViewでZoomIn - ZoomOutアニメーションを実行しました。
Res- > animフォルダーにアニメーションxmlを追加します。
Zoom_in_out.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<scale
android:duration="1000"
android:fillAfter="false"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1.2"
android:toYScale="1.2" />
<set android:interpolator="@android:anim/decelerate_interpolator">
<scale
android:duration="1000"
android:fillBefore="false"
android:fromXScale="1.2"
android:fromYScale="1.2"
android:pivotX="50%"
android:pivotY="50%"
android:startOffset="500"
android:toXScale="1.0"
android:toYScale="1.0" />
</set>
</set>
texture_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<TextureView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textureView"
android:layout_margin="50dp"
android:background="@android:color/darker_gray"
android:layout_width="wrap_content" android:layout_height="wrap_content">
</TextureView>
TextureViewActivity.java:
import android.graphics.SurfaceTexture;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Surface;
import android.view.TextureView;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import java.io.IOException;
public class TextureViewActivity extends AppCompatActivity implements TextureView.SurfaceTextureListener {
private TextureView textureView;
private MediaPlayer mMediaPlayer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.texture_layout);
textureView = (TextureView)findViewById(R.id.textureView);
textureView.setSurfaceTextureListener(this);
textureView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Animation zoomAnimation = AnimationUtils.loadAnimation(TextureViewActivity.this, R.anim.zoom_in_out);
textureView.startAnimation(zoomAnimation);
}
});
}
private String getVideoPath(){
return "android.resource://" + getPackageName() + "/" + R.raw.promovideo;
}
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int width, int height) {
Surface surface = new Surface(surfaceTexture);
try {
mMediaPlayer= new MediaPlayer();
mMediaPlayer.setDataSource(TextureViewActivity.this, Uri.parse(getVideoPath()));
mMediaPlayer.setSurface(surface);
mMediaPlayer.prepare();
mMediaPlayer.start();
mMediaPlayer.setLooping(true);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
}
@Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
return false;
}
@Override
public void onSurfaceTextureUpdated(SurfaceTexture surface) {
}
}
終わり