VideoDurationView.java
2.36 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
package com.wd.player.durationview;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.aliyun.svideo.wd.player.R;
import com.wd.foundation.bean.utils.TimeFormater;
import com.wd.foundation.wdkit.utils.FilletUtil;
/**
* 右下角视频时长显示
*/
public class VideoDurationView extends RelativeLayout {
private static final String TAG = VideoDurationView.class.getSimpleName();
private TextView tv_duration;
private boolean needTagBg;
public VideoDurationView(Context context) {
super(context);
init(context, null);
}
public VideoDurationView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public VideoDurationView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}
private void init(Context context, AttributeSet attrs) {
LayoutInflater inflater =
(LayoutInflater) getContext().getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.view_video_duration, null);
LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
addView(view, params);
if (attrs != null){
TypedArray typeArray = context.obtainStyledAttributes(attrs, R.styleable.VideoDurationBgStyle);
needTagBg = typeArray.getBoolean(R.styleable.VideoDurationBgStyle_need_video_duration_bg,true);
}
tv_duration = view.findViewById(R.id.tv_duration);
tv_duration.setTypeface(Typeface.createFromAsset(tv_duration.getContext().getAssets(), "ttf/BebasNeue.ttf"));
//设置圆角 透明度是50%,颜色是#000000,圆角是2
if (needTagBg){
FilletUtil.setRoundBg(tv_duration,"#4D000000",getContext().getResources().getDimension(R.dimen.rmrb_dp2));
}
}
/**
* 时长
* @param duration 时长
*/
public void setDuration(long duration) {
if (tv_duration != null){
tv_duration.setText(TimeFormater.formatMs(duration));
}
}
}