PlayerVodFragment.java
4.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package com.cnlive.gundam.video.fragment;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.cnlive.gundam.R;
import com.cnlive.gundam.databinding.FragmentPlayerVodBinding;
import com.cnlive.gundam.main.model.VideoListProgram;
import com.cnlive.gundam.video.fragment.chat.CommentFragment;
import com.cnlive.gundam.video.model.VideoModel;
import com.cnlive.gundam.video.utils.PlayerUtils;
import com.cnlive.gundam.video.view.PlayerAccelerometerSensor;
import com.cnlive.libs.util.ProbeUtil;
/**
* Created by gujun on 2017/4/6.
*/
public class PlayerVodFragment extends Fragment implements PlayerAccelerometerSensor.ScreenOrientationListener {
private VideoListProgram program;
private FragmentPlayerVodBinding binding;
private PlayerAccelerometerSensor playerAccelerometerSensor;
public static PlayerVodFragment newInstance(VideoListProgram program) {
Bundle args = new Bundle();
args.putSerializable("program", program);
PlayerVodFragment fragment = new PlayerVodFragment();
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
playerAccelerometerSensor = new PlayerAccelerometerSensor(getActivity());
playerAccelerometerSensor.setScreenOrientationListener(this);
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_player_vod, container, false);
VideoListProgram program = (VideoListProgram) getArguments().getSerializable("program");
getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.contentLayout, CommentFragment.newInstance(program.getvId()+""), "commentFragment").commit();
return binding.getRoot();
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
init();
}
private void init() {
program = (VideoListProgram) getArguments().getSerializable("program");
if (program == null) return;
VideoModel videoModel = new VideoModel(program.getTitle(), program.getvId(), program.getType(), program.getRates());
ProbeUtil.probeSDK("pgcVodCount");//点播播放数量统计
binding.videoView.setVideoInfo(videoModel);
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
boolean isPortrait = PlayerUtils.isPortrait(getActivity());
binding.videoView.onScreenChange(isPortrait);
PlayerUtils.setStatusBarVisibility(getActivity(), isPortrait);
}
@Override
public void onResume() {
super.onResume();
binding.videoView.onResume();
playerAccelerometerSensor.register();
}
@Override
public void onPause() {
super.onPause();
binding.videoView.onPause();
playerAccelerometerSensor.unregister();
}
@Override
public void onDestroyView() {
binding.videoView.onDestroy();
super.onDestroyView();
}
@Override
public void onOrientationChange(int orientation) {
if (orientation == PlayerAccelerometerSensor.ORIENTATION_PORTRAIT) {
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
} else if (orientation == PlayerAccelerometerSensor.ORIENTATION_LANDSCAPE) {
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
} else if (orientation == PlayerAccelerometerSensor.ORIENTATION_REVERSE_LANDSCAPE) {
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
}
}
}