我在获取片段(SimpleExoPlayerView
)过渡动画以便fadein
和fadeout
正常工作时遇到问题。在过渡期间,如果我将持续时间设置为5秒,我将看到5秒的黑屏。奇怪的是,过渡动画适用于其他动画类型,例如水平滑入和滑出。我只是无法弄清楚我的编码有什么问题,希望有人可以提供帮助....下面是代码
<?xml version="1.0" encoding="utf-8" ?>
<objectAnimator
xmlns:android="http://schemas.android.com/apk/res/android"
android:valueFrom="0.0"
android:valueTo="1.0"
android:valueType="floatType"
android:propertyName="alpha"
android:duration="5000" />
/res/animator/fade_out.xml ================================================== =================
MainActivity中的代码
VideoFragment videoFragment = new VideoFragment();
videoFragment.setArguments(bundle); fm = getFragmentManager();
ft = fm.beginTransaction();
ft.setCustomAnimations(R.animator.fade_in, R.animator.fade_out); ft.replace(R.id.fragment_place, videoFragment);
ft.addToBackStack(null);
ft.commit();
videoFragment中的代码
public class VideoFragment extends Fragment {
private final String TAG = "Video Fragment";
private Uri videoUri;
private String filePath;
private String filename;
private Integer duration;
private Integer currentIndex;
private Context mContext;
private SimpleExoPlayerView playerView;
private SimpleExoPlayer videoPlayer;
private long playbackPosition;
private int currentWindow;
private boolean playWhenReady = true;
private View v;
public VideoFragment() {
// Required empty public constructor
}
@Override
public void onStart() {
super.onStart();
initializePlayer();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
v = inflater.inflate(R.layout.fragment_video, container, false);
playerView = (SimpleExoPlayerView) v.findViewById(R.id.video_view);
mContext = container.getContext();
filePath = getArguments().getString("filepath");
filename = getArguments().getString("filename");
duration = getArguments().getInt("duration");
currentIndex = getArguments().getInt("currentIndex");
return v;
}
//===============================================================================
// Initialize Player
//=============================================================================
private void initializePlayer() {
videoPlayer = ExoPlayerFactory.newSimpleInstance( new DefaultRenderersFactory(mContext), new DefaultTrackSelector(), new DefaultLoadControl());
videoPlayer.addListener(new Player.EventListener() {
@Override
public void onTimelineChanged(Timeline timeline, Object manifest) {
}
@Override
public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
}
@Override
public void onLoadingChanged(boolean isLoading) {
}
@Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
if (playbackState == Player.STATE_ENDED) {
releasePlayer();
((MainActivity) getActivity()).executePlaylist(currentIndex + 1);
}
}
@Override
public void onRepeatModeChanged(int repeatMode) {
}
@Override
public void onPlayerError(ExoPlaybackException error) {
}
@Override
public void onPositionDiscontinuity() {
}
@Override
public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) {
}
});
playerView.setPlayer(videoPlayer);
playerView.setUseController(false);
videoPlayer.setPlayWhenReady(playWhenReady);
//videoPlayer.seekTo(currentWindow, playbackPosition);
MediaSource mediaSource = buildMediaSource(mContext);
videoPlayer.prepare(mediaSource, true, false);
}
//==============================================================================================
// Prepare Video Source
//==============================================================================================
private MediaSource buildMediaSource(Context context) {
File dir = new File(filePath);
File file = new File(dir, filename);
videoUri = Uri.fromFile(file);
// these are reused for both media sources we create below
DefaultExtractorsFactory extractorsFactory =
new DefaultExtractorsFactory();
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(context, Util.getUserAgent(context, "DanSignage"), null);
ExtractorMediaSource videoSource = new ExtractorMediaSource(videoUri, dataSourceFactory, extractorsFactory, null, null);
return videoSource;
}
//======================================================
// Release Video Player
//===============================================================
private void releasePlayer () {
if (videoPlayer != null) {
playbackPosition = videoPlayer.getCurrentPosition();
currentWindow = videoPlayer.getCurrentWindowIndex();
playWhenReady = videoPlayer.getPlayWhenReady();
videoPlayer.release();
videoPlayer = null;
}
}
}