@@ -22,7 +22,6 @@ import org.videolan.libvlc.MediaPlayer
22
22
import org.videolan.libvlc.interfaces.IMedia
23
23
import org.videolan.libvlc.util.VLCVideoLayout
24
24
import java.io.File
25
- import kotlin.math.abs
26
25
27
26
/* *
28
27
* Created by xyoye on 2021/4/12.
@@ -42,8 +41,7 @@ class VlcVideoPlayer(private val mContext: Context) : AbstractVideoPlayer() {
42
41
private lateinit var mMediaPlayer: MediaPlayer
43
42
private lateinit var mMedia: Media
44
43
45
- private val progress = Progress ()
46
- private var lastTime = 0L
44
+ private var mCurrentDuration = 0L
47
45
private var seekable = true
48
46
private var isBufferEnd = false
49
47
@@ -77,18 +75,19 @@ class VlcVideoPlayer(private val mContext: Context) : AbstractVideoPlayer() {
77
75
mMedia = Media (libVlc, videoUri)
78
76
79
77
// 是否开启硬件加速
80
- if (PlayerInitializer .Player .vlcHWDecode == VLCHWDecode .HW_ACCELERATION_DISABLE ){
78
+ if (PlayerInitializer .Player .vlcHWDecode == VLCHWDecode .HW_ACCELERATION_DISABLE ) {
81
79
mMedia.setHWDecoderEnabled(false , false )
82
80
} else if (PlayerInitializer .Player .vlcHWDecode == VLCHWDecode .HW_ACCELERATION_DECODING ||
83
- PlayerInitializer .Player .vlcHWDecode == VLCHWDecode .HW_ACCELERATION_FULL ){
81
+ PlayerInitializer .Player .vlcHWDecode == VLCHWDecode .HW_ACCELERATION_FULL
82
+ ) {
84
83
mMedia.setHWDecoderEnabled(true , true )
85
- if (PlayerInitializer .Player .vlcHWDecode == VLCHWDecode .HW_ACCELERATION_DECODING ){
84
+ if (PlayerInitializer .Player .vlcHWDecode == VLCHWDecode .HW_ACCELERATION_DECODING ) {
86
85
mMedia.addOption(" :no-mediacodec-dr" )
87
86
mMedia.addOption(" :no-omxil-dr" )
88
87
}
89
88
} /* else automatic: use default options */
90
89
91
- progress.duration = mMedia.duration
90
+ mCurrentDuration = mMedia.duration
92
91
mMediaPlayer.media = mMedia
93
92
mMedia.release()
94
93
}
@@ -111,8 +110,6 @@ class VlcVideoPlayer(private val mContext: Context) : AbstractVideoPlayer() {
111
110
112
111
override fun stop () {
113
112
playbackState = PlaybackStateCompat .STATE_STOPPED
114
- progress.release()
115
- lastTime = 0
116
113
117
114
mMediaPlayer.stop()
118
115
}
@@ -178,11 +175,11 @@ class VlcVideoPlayer(private val mContext: Context) : AbstractVideoPlayer() {
178
175
}
179
176
180
177
override fun getCurrentPosition (): Long {
181
- return progress.position
178
+ return mMediaPlayer.time
182
179
}
183
180
184
181
override fun getDuration (): Long {
185
- return progress.duration
182
+ return mCurrentDuration
186
183
}
187
184
188
185
override fun getSpeed (): Float {
@@ -227,7 +224,8 @@ class VlcVideoPlayer(private val mContext: Context) : AbstractVideoPlayer() {
227
224
}
228
225
}
229
226
// 打开中
230
- MediaPlayer .Event .Opening -> {}
227
+ MediaPlayer .Event .Opening -> {
228
+ }
231
229
// 播放中
232
230
MediaPlayer .Event .Playing -> playbackState = PlaybackStateCompat .STATE_PLAYING
233
231
// 已暂停
@@ -242,15 +240,7 @@ class VlcVideoPlayer(private val mContext: Context) : AbstractVideoPlayer() {
242
240
}
243
241
// 时长输出
244
242
MediaPlayer .Event .LengthChanged -> {
245
- progress.duration = it.lengthChanged
246
- }
247
- // 进度改变
248
- MediaPlayer .Event .TimeChanged -> {
249
- val currentTime = it.timeChanged
250
- if (abs(currentTime - lastTime) > 950L ) {
251
- progress.position = currentTime
252
- lastTime = currentTime
253
- }
243
+ mCurrentDuration = it.lengthChanged
254
244
}
255
245
// 视频输出
256
246
MediaPlayer .Event .Vout -> {
@@ -292,12 +282,4 @@ class VlcVideoPlayer(private val mContext: Context) : AbstractVideoPlayer() {
292
282
293
283
private fun isVideoPlaying () =
294
284
! mMediaPlayer.isReleased && mMediaPlayer.vlcVout.areViewsAttached()
295
-
296
- class Progress (var position : Long = 0L , var duration : Long = 0L ) {
297
-
298
- fun release () {
299
- position = 0L
300
- duration = 0L
301
- }
302
- }
303
285
}
0 commit comments