PlayerUgcLiveFragment.java
3.74 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
111
112
package com.cnlive.gundam.video.fragment;
import android.Manifest;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import com.cnlive.gundam.R;
import com.cnlive.gundam.databinding.FragmentPlayerUgcLiveBinding;
import com.cnlive.gundam.main.model.VideoListProgram;
import com.cnlive.gundam.video.model.VideoModel;
import com.cnlive.gundam.video.utils.PlayerUtils;
import com.cnlive.gundam.video.view.BaseVideoView;
import com.cnlive.gundam.video.view.VideoView;
/**
* Created by gujun on 2017/4/5.
*/
public class PlayerUgcLiveFragment extends Fragment implements BaseVideoView.OnUgcLiveStatusPermissionListener{
private final int PERMISSION_REQUEST_CODE = 0x1001;
private FragmentPlayerUgcLiveBinding binding;
private VideoListProgram program;
private String title;
private String id;
private String rates;
public static PlayerUgcLiveFragment newInstance(VideoListProgram program) {
Bundle args = new Bundle();
args.putSerializable("program", program);
PlayerUgcLiveFragment fragment = new PlayerUgcLiveFragment();
fragment.setArguments(args);
return fragment;
}
private void initData() {
program = (VideoListProgram) getArguments().getSerializable("program");
title = program.getTitle();
id = program.getChannelId();
rates = program.getRates();
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_player_ugc_live, container, false);
initData();
return binding.getRoot();
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
binding.videoView.setUgcLiveStatusPermissionListener(this);//必须在设置播放数据前调用
binding.videoView.setVideoInfo(new VideoModel(title, id, VideoView.TYPE_UGC_LIVE, rates));
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
boolean isPortrait = PlayerUtils.isPortrait(getActivity());
binding.videoView.onScreenChange(isPortrait);
}
@Override
public void onResume() {
super.onResume();
binding.videoView.onResume();
}
@Override
public void onPause() {
super.onPause();
binding.videoView.onPause();
}
@Override
public void onDestroyView() {
binding.videoView.onDestroy();
super.onDestroyView();
}
@Override
public void onShouldRequestPermission() {
requestPermissions(new String[]{Manifest.permission.READ_PHONE_STATE}, PERMISSION_REQUEST_CODE);
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if(requestCode == PERMISSION_REQUEST_CODE){
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
if(binding != null && binding.videoView != null)
binding.videoView.addUgcLiveStatus();
} else {
Toast.makeText(getActivity(), "权限已被禁止,您将接收不到直播状态", Toast.LENGTH_LONG).show();
}
}
}
}