Search in sources :

Example 1 with VideoPlayerView

use of com.volokh.danylo.video_player_manager.ui.VideoPlayerView in project VideoPlayerManager by danylovolokh.

the class VideoPlayerManagerFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View root = inflater.inflate(R.layout.video_player_manager_fragment, container, false);
    try {
        mVideoFileDecriptor_sample_1 = getActivity().getAssets().openFd("video_sample_1.mp4");
        mVideoFileDecriptor_sample_2 = getActivity().getAssets().openFd("video_sample_2.mp4");
    } catch (IOException e) {
        e.printStackTrace();
    }
    mVideoPlayer_1 = (VideoPlayerView) root.findViewById(R.id.video_player_1);
    mVideoPlayer_1.addMediaPlayerListener(new SimpleMainThreadMediaPlayerListener() {

        @Override
        public void onVideoPreparedMainThread() {
            // We hide the cover when video is prepared. Playback is about to start
            mVideoCover.setVisibility(View.INVISIBLE);
        }

        @Override
        public void onVideoStoppedMainThread() {
            // We show the cover when video is stopped
            mVideoCover.setVisibility(View.VISIBLE);
        }

        @Override
        public void onVideoCompletionMainThread() {
            // We show the cover when video is completed
            mVideoCover.setVisibility(View.VISIBLE);
        }
    });
    mVideoCover = (ImageView) root.findViewById(R.id.video_cover_1);
    mVideoCover.setOnClickListener(this);
    mVideoPlayer_2 = (VideoPlayerView) root.findViewById(R.id.video_player_2);
    mVideoPlayer_2.addMediaPlayerListener(new SimpleMainThreadMediaPlayerListener() {

        @Override
        public void onVideoPreparedMainThread() {
            // We hide the cover when video is prepared. Playback is about to start
            mVideoCover2.setVisibility(View.INVISIBLE);
        }

        @Override
        public void onVideoStoppedMainThread() {
            // We show the cover when video is stopped
            mVideoCover2.setVisibility(View.VISIBLE);
        }

        @Override
        public void onVideoCompletionMainThread() {
            // We show the cover when video is completed
            mVideoCover2.setVisibility(View.VISIBLE);
        }
    });
    mVideoCover2 = (ImageView) root.findViewById(R.id.video_cover_2);
    mVideoCover2.setOnClickListener(this);
    Picasso.with(getActivity()).load(R.drawable.video_sample_1_pic).into(mVideoCover);
    Picasso.with(getActivity()).load(R.drawable.video_sample_2_pic).into(mVideoCover2);
    return root;
}
Also used : SimpleMainThreadMediaPlayerListener(com.volokh.danylo.video_player_manager.ui.SimpleMainThreadMediaPlayerListener) IOException(java.io.IOException) ImageView(android.widget.ImageView) VideoPlayerView(com.volokh.danylo.video_player_manager.ui.VideoPlayerView) View(android.view.View) Nullable(android.support.annotation.Nullable)

Aggregations

Nullable (android.support.annotation.Nullable)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 SimpleMainThreadMediaPlayerListener (com.volokh.danylo.video_player_manager.ui.SimpleMainThreadMediaPlayerListener)1 VideoPlayerView (com.volokh.danylo.video_player_manager.ui.VideoPlayerView)1 IOException (java.io.IOException)1