Skip to content

Commit 8bd5bb4

Browse files
committed
增加设置播放器背景色的方法
1 parent d53f163 commit 8bd5bb4

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

dkplayer-java/src/main/java/com/dueeeke/videoplayer/player/VideoView.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ public class VideoView<P extends AbstractPlayer> extends FrameLayout
124124
*/
125125
protected boolean mIsLooping;
126126

127+
/**
128+
* {@link #mPlayerContainer}背景色,默认黑色
129+
*/
130+
private int mPlayerBackgroundColor;
131+
127132
public VideoView(@NonNull Context context) {
128133
this(context, null);
129134
}
@@ -148,6 +153,7 @@ public VideoView(@NonNull Context context, @Nullable AttributeSet attrs, int def
148153
mEnableAudioFocus = a.getBoolean(R.styleable.VideoView_enableAudioFocus, mEnableAudioFocus);
149154
mIsLooping = a.getBoolean(R.styleable.VideoView_looping, false);
150155
mCurrentScreenScaleType = a.getInt(R.styleable.VideoView_screenScaleType, mCurrentScreenScaleType);
156+
mPlayerBackgroundColor = a.getColor(R.styleable.VideoView_playerBackgroundColor, Color.BLACK);
151157
a.recycle();
152158

153159
initView();
@@ -158,13 +164,20 @@ public VideoView(@NonNull Context context, @Nullable AttributeSet attrs, int def
158164
*/
159165
protected void initView() {
160166
mPlayerContainer = new FrameLayout(getContext());
161-
mPlayerContainer.setBackgroundColor(Color.BLACK);
167+
mPlayerContainer.setBackgroundColor(mPlayerBackgroundColor);
162168
LayoutParams params = new LayoutParams(
163169
ViewGroup.LayoutParams.MATCH_PARENT,
164170
ViewGroup.LayoutParams.MATCH_PARENT);
165171
this.addView(mPlayerContainer, params);
166172
}
167173

174+
/**
175+
* 设置{@link #mPlayerContainer}的背景色
176+
*/
177+
public void setPlayerBackgroundColor(int color) {
178+
mPlayerContainer.setBackgroundColor(color);
179+
}
180+
168181
/**
169182
* 开始播放,注意:调用此方法后必须调用{@link #release()}释放播放器,否则会导致内存泄漏
170183
*/

dkplayer-java/src/main/res/values/attrs.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
<declare-styleable name="VideoView">
44
<attr name="looping" format="boolean"/>
55
<attr name="enableAudioFocus" format="boolean"/>
6-
76
<attr name="screenScaleType" format="dimension">
87
<enum name="type_default" value="0"/>
98
<enum name="type_16_9" value="1"/>
@@ -12,5 +11,6 @@
1211
<enum name="type_original" value="4"/>
1312
<enum name="type_center_crop" value="5"/>
1413
</attr>
14+
<attr name="playerBackgroundColor" format="color"/>
1515
</declare-styleable>
1616
</resources>

0 commit comments

Comments
 (0)