-
Notifications
You must be signed in to change notification settings - Fork 515
/
JzvdStdSpeed.java
96 lines (82 loc) · 2.5 KB
/
JzvdStdSpeed.java
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
package cn.jzvd.demo.CustomJzvd;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;
import cn.jzvd.JzvdStd;
import cn.jzvd.demo.R;
public class JzvdStdSpeed extends JzvdStd {
TextView tvSpeed;
int currentSpeedIndex = 2;
public JzvdStdSpeed(Context context) {
super(context);
}
public JzvdStdSpeed(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public void init(Context context) {
super.init(context);
tvSpeed = findViewById(R.id.tv_speed);
tvSpeed.setOnClickListener(this);
}
public void setScreenNormal() {
super.setScreenNormal();
tvSpeed.setVisibility(View.GONE);
}
@Override
public void setScreenFullscreen() {
super.setScreenFullscreen();
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M)
tvSpeed.setVisibility(View.VISIBLE);
if (jzDataSource.objects == null) {
Object[] object = {2};
jzDataSource.objects = object;
currentSpeedIndex = 2;
} else {
currentSpeedIndex = (int) jzDataSource.objects[0];
}
if (currentSpeedIndex == 2) {
tvSpeed.setText("倍速");
} else {
tvSpeed.setText(getSpeedFromIndex(currentSpeedIndex) + "X");
}
}
@Override
public void onClick(View v) {
super.onClick(v);
if (v.getId() == R.id.tv_speed) {//0.5 0.75 1.0 1.25 1.5 1.75 2.0
if (currentSpeedIndex == 6) {
currentSpeedIndex = 0;
} else {
currentSpeedIndex += 1;
}
mediaInterface.setSpeed(getSpeedFromIndex(currentSpeedIndex));
tvSpeed.setText(getSpeedFromIndex(currentSpeedIndex) + "X");
jzDataSource.objects[0] = currentSpeedIndex;
}
}
@Override
public int getLayoutId() {
return R.layout.layout_std_speed;
}
private float getSpeedFromIndex(int index) {
float ret = 0f;
if (index == 0) {
ret = 0.5f;
} else if (index == 1) {
ret = 0.75f;
} else if (index == 2) {
ret = 1.0f;
} else if (index == 3) {
ret = 1.25f;
} else if (index == 4) {
ret = 1.5f;
} else if (index == 5) {
ret = 1.75f;
} else if (index == 6) {
ret = 2.0f;
}
return ret;
}
}