Skip to content

Commit df7a131

Browse files
committed
[新增功能](master): 新增自动播放下一集
1 parent 20ca60a commit df7a131

File tree

6 files changed

+44
-0
lines changed

6 files changed

+44
-0
lines changed

player_component/src/main/java/com/xyoye/player/controller/VideoController.kt

+10
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import com.xyoye.player.controller.video.LoadingView
2525
import com.xyoye.player.controller.video.PlayerBottomView
2626
import com.xyoye.player.controller.video.PlayerGestureView
2727
import com.xyoye.player.controller.video.PlayerTopView
28+
import com.xyoye.player.info.PlayerInitializer
2829
import com.xyoye.player.utils.MessageTime
2930
import com.xyoye.player_component.R
3031
import com.xyoye.player_component.databinding.LayoutPlayerControllerBinding
@@ -60,6 +61,7 @@ class VideoController(
6061

6162
private var mDanmuSourceChanged: ((String, Int) -> Unit)? = null
6263
private var mSubtitleSourceChanged: ((String) -> Unit)? = null
64+
private var switchVideoSourceBlock: ((Int) -> Unit)? = null
6365

6466
private val controllerBinding = DataBindingUtil.inflate<LayoutPlayerControllerBinding>(
6567
LayoutInflater.from(context),
@@ -145,6 +147,13 @@ class VideoController(
145147
super.onPlayStateChanged(playState)
146148
if (playState == PlayState.STATE_PLAYING) {
147149
considerSeekToLastPlay()
150+
} else if (playState == PlayState.STATE_COMPLETED) {
151+
if (PlayerInitializer.Player.isAutoPlayNext) {
152+
val videoSource = mControlWrapper.getVideoSource()
153+
if (videoSource.hasNextSource()) {
154+
switchVideoSourceBlock?.invoke(videoSource.getGroupIndex() + 1)
155+
}
156+
}
148157
}
149158
}
150159

@@ -250,6 +259,7 @@ class VideoController(
250259
* 切换视频资源回调
251260
*/
252261
fun setSwitchVideoSourceBlock(block: (Int) -> Unit) {
262+
this.switchVideoSourceBlock = block
253263
playerBotView.setSwitchVideoSourceBlock(block)
254264
mSettingController.setSwitchVideoSourceBlock(block)
255265
}

player_component/src/main/java/com/xyoye/player/controller/setting/SettingPlayerView.kt

+6
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ class SettingPlayerView(
6969
PlayerInitializer.isOrientationEnabled = isChecked
7070
}
7171

72+
viewBinding.autoPlayNextSw.isChecked = PlayerInitializer.Player.isAutoPlayNext
73+
viewBinding.autoPlayNextSw.setOnCheckedChangeListener { _, isChecked ->
74+
PlayerInitializer.Player.isAutoPlayNext = isChecked
75+
PlayerConfig.putAutoPlayNext(isChecked)
76+
}
77+
7278
for (data in mVideoScaleData) {
7379
if (data.screenScale == PlayerInitializer.screenScale) {
7480
data.isChecked = true

player_component/src/main/java/com/xyoye/player/info/PlayerInitializer.kt

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ object PlayerInitializer {
2727
var vlcPixelFormat = VLCPixelFormat.PIXEL_RGB_32
2828
var vlcHWDecode = VLCHWDecode.HW_ACCELERATION_AUTO
2929
var videoSpeed = 25
30+
var isAutoPlayNext = true
3031
}
3132

3233
object Danmu {

player_component/src/main/java/com/xyoye/player_component/ui/activities/player/PlayerActivity.kt

+2
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,8 @@ class PlayerActivity : BaseActivity<PlayerViewModel, ActivityPlayerBinding>(),
309309
if (PlayerConfig.isUseSurfaceView()) SurfaceType.VIEW_SURFACE else SurfaceType.VIEW_TEXTURE
310310
//视频速度
311311
PlayerInitializer.Player.videoSpeed = PlayerConfig.getVideoSpeed()
312+
//自动播放下一集
313+
PlayerInitializer.Player.isAutoPlayNext = PlayerConfig.isAutoPlayNext()
312314

313315
//VLCPlayer像素格式
314316
PlayerInitializer.Player.vlcPixelFormat =

player_component/src/main/res/layout/layout_setting_player.xml

+24
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,30 @@
5050
android:layout_centerVertical="true" />
5151
</RelativeLayout>
5252

53+
<RelativeLayout
54+
android:layout_width="match_parent"
55+
android:layout_height="wrap_content"
56+
android:layout_marginStart="10dp"
57+
android:layout_marginTop="10dp"
58+
android:layout_marginEnd="10dp">
59+
60+
<TextView
61+
android:layout_width="wrap_content"
62+
android:layout_height="wrap_content"
63+
android:layout_centerVertical="true"
64+
android:text="@string/text_auto_play_next"
65+
android:textColor="@color/text_white_immutable"
66+
android:textSize="14sp" />
67+
68+
<androidx.appcompat.widget.SwitchCompat
69+
android:id="@+id/auto_play_next_sw"
70+
style="@style/Widget.AppCompat.CompoundButton.Switch"
71+
android:layout_width="wrap_content"
72+
android:layout_height="wrap_content"
73+
android:layout_alignParentEnd="true"
74+
android:layout_centerVertical="true" />
75+
</RelativeLayout>
76+
5377
<TextView
5478
android:layout_width="wrap_content"
5579
android:layout_height="wrap_content"

player_component/src/main/res/values/strings.xml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
<string name="text_setting_player">播放器设置</string>
1111
<string name="text_orientation_changeable">开启屏幕翻转</string>
12+
<string name="text_auto_play_next">自动播放下一集</string>
1213
<string name="text_video_scale_type">视频比例</string>
1314
<string name="text_video_speed">播放速度</string>
1415
<string name="text_audio_stream">音频流</string>

0 commit comments

Comments
 (0)