-
Notifications
You must be signed in to change notification settings - Fork 531
/
Copy pathJzvdStdVolume.java
72 lines (61 loc) · 2.06 KB
/
JzvdStdVolume.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
package cn.jzvd.demo.CustomJzvd;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import cn.jzvd.JzvdStd;
import cn.jzvd.demo.R;
public class JzvdStdVolume extends JzvdStd {
ImageView ivVolume;
boolean volumeOpen;
public JzvdStdVolume(Context context) {
super(context);
}
public JzvdStdVolume(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public void init(Context context) {
super.init(context);
ivVolume = findViewById(R.id.volume);
ivVolume.setOnClickListener(this);
}
@Override
public void onPrepared() {
super.onPrepared();
if (screen == SCREEN_FULLSCREEN) {
mediaInterface.setVolume(1f, 1f);
ivVolume.setImageResource(R.drawable.ic_volume_open);
} else {
mediaInterface.setVolume(volumeOpen ? 1f : 0f, volumeOpen ? 1f : 0f);
ivVolume.setImageResource(volumeOpen ? R.drawable.ic_volume_open : R.drawable.ic_volume_close);
}
}
@Override
public void setScreenNormal() {
super.setScreenNormal();
if (mediaInterface != null && !volumeOpen)
mediaInterface.setVolume(0f, 0f);
ivVolume.setImageResource(volumeOpen ? R.drawable.ic_volume_open : R.drawable.ic_volume_close);
}
@Override
public void setScreenFullscreen() {
super.setScreenFullscreen();
if (mediaInterface != null)
mediaInterface.setVolume(1f, 1f);
ivVolume.setImageResource(R.drawable.ic_volume_open);
}
@Override
public void onClick(View v) {
super.onClick(v);
if (v.getId() == R.id.volume) {
volumeOpen = !volumeOpen;
mediaInterface.setVolume(volumeOpen ? 1f : 0f, volumeOpen ? 1f : 0f);
ivVolume.setImageResource(volumeOpen ? R.drawable.ic_volume_open : R.drawable.ic_volume_close);
}
}
@Override
public int getLayoutId() {
return R.layout.layout_std_with_volume_button;
}
}