@@ -15,7 +15,7 @@ import com.skyd.anivu.model.preference.player.HardwareDecodePreference
15
15
import com.skyd.anivu.model.preference.player.PlayerMaxBackCacheSizePreference
16
16
import com.skyd.anivu.model.preference.player.PlayerMaxCacheSizePreference
17
17
import com.skyd.anivu.model.preference.player.PlayerSeekOptionPreference
18
- import com.skyd.anivu.ui.mpv.controller.bar.toDurationString
18
+ import com.skyd.anivu.ui.mpv.land. controller.bar.toDurationString
19
19
import `is`.xyz.mpv.MPVLib
20
20
import `is`.xyz.mpv.MPVLib.mpvFormat.MPV_FORMAT_DOUBLE
21
21
import `is`.xyz.mpv.MPVLib.mpvFormat.MPV_FORMAT_FLAG
@@ -91,6 +91,7 @@ class MPVPlayer(private val context: Application) : SurfaceHolder.Callback, MPVL
91
91
MPVLib .setOptionString(" save-position-on-quit" , " no" )
92
92
// would crash before the surface is attached
93
93
MPVLib .setOptionString(" force-window" , " no" )
94
+ MPVLib .setOptionString(" vo" , " null" )
94
95
// "no" wouldn't work and "yes" is not intended by the UI
95
96
MPVLib .setOptionString(" idle" , " yes" )
96
97
MPVLib .setPropertyString(" sub-fonts-dir" , fontDir)
@@ -119,7 +120,6 @@ class MPVPlayer(private val context: Application) : SurfaceHolder.Callback, MPVL
119
120
MPVLib .setOptionString(" display-fps-override" , refreshRate.toString())
120
121
MPVLib .setOptionString(" video-sync" , " audio" )
121
122
122
- MPVLib .setOptionString(" vo" , vo)
123
123
MPVLib .setOptionString(" gpu-context" , " android" )
124
124
MPVLib .setOptionString(" opengl-es" , " yes" )
125
125
MPVLib .setOptionString(
@@ -232,7 +232,7 @@ class MPVPlayer(private val context: Application) : SurfaceHolder.Callback, MPVL
232
232
}
233
233
}
234
234
235
- data class Track (val trackId : Int , val name : String )
235
+ data class Track (val trackId : Int , val name : String , val isAlbumArt : Boolean )
236
236
237
237
private var tracks = mapOf<String , MutableList <Track >>(
238
238
" audio" to mutableListOf (),
@@ -258,28 +258,9 @@ class MPVPlayer(private val context: Application) : SurfaceHolder.Callback, MPVL
258
258
}
259
259
260
260
fun loadTracks () {
261
- for (list in tracks.values) {
262
- list.clear()
263
- // pseudo-track to allow disabling audio/subs
264
- list.add(Track (- 1 , context.getString(R .string.track_off)))
265
- }
266
- val count = MPVLib .getPropertyInt(" track-list/count" ) ? : 0
267
- // Note that because events are async, properties might disappear at any moment
268
- // so use ?: continue instead of !!
269
- for (i in 0 until count) {
270
- val type = MPVLib .getPropertyString(" track-list/$i /type" ) ? : continue
271
- if (! tracks.containsKey(type)) {
272
- Log .w(TAG , " Got unknown track type: $type " )
273
- continue
274
- }
275
- val mpvId = MPVLib .getPropertyInt(" track-list/$i /id" ) ? : continue
276
- val lang = MPVLib .getPropertyString(" track-list/$i /lang" )
277
- val title = MPVLib .getPropertyString(" track-list/$i /title" )
278
-
279
- tracks.getValue(type).add(
280
- Track (trackId = mpvId, name = getTrackDisplayName(mpvId, lang, title))
281
- )
282
- }
261
+ loadTrack(" sub" )
262
+ loadTrack(" audio" )
263
+ loadTrack(" video" )
283
264
}
284
265
285
266
fun loadSubtitleTrack () = loadTrack(" sub" )
@@ -288,7 +269,13 @@ class MPVPlayer(private val context: Application) : SurfaceHolder.Callback, MPVL
288
269
private fun loadTrack (trackType : String ) {
289
270
tracks[trackType]!! .apply {
290
271
clear()
291
- add(Track (- 1 , context.getString(R .string.track_off)))
272
+ add(
273
+ Track (
274
+ trackId = - 1 ,
275
+ name = context.getString(R .string.track_off),
276
+ isAlbumArt = false ,
277
+ )
278
+ )
292
279
}
293
280
val count = MPVLib .getPropertyInt(" track-list/count" )
294
281
// Note that because events are async, properties might disappear at any moment
@@ -299,9 +286,14 @@ class MPVPlayer(private val context: Application) : SurfaceHolder.Callback, MPVL
299
286
val mpvId = MPVLib .getPropertyInt(" track-list/$i /id" ) ? : continue
300
287
val lang = MPVLib .getPropertyString(" track-list/$i /lang" )
301
288
val title = MPVLib .getPropertyString(" track-list/$i /title" )
289
+ val isAlbumArt = MPVLib .getPropertyBoolean(" track-list/$i /albumart" )
302
290
303
291
tracks.getValue(type).add(
304
- Track (trackId = mpvId, name = getTrackDisplayName(mpvId, lang, title))
292
+ Track (
293
+ trackId = mpvId,
294
+ name = getTrackDisplayName(mpvId, lang, title),
295
+ isAlbumArt = isAlbumArt,
296
+ )
305
297
)
306
298
}
307
299
}
@@ -342,11 +334,15 @@ class MPVPlayer(private val context: Application) : SurfaceHolder.Callback, MPVL
342
334
// Property getters/setters
343
335
val filename: String?
344
336
get() = MPVLib .getPropertyString(" filename" )
337
+ val path: String?
338
+ get() = MPVLib .getPropertyString(" path" )
345
339
val mediaTitle: String?
346
340
get() = MPVLib .getPropertyString(" media-title" )
347
341
var paused: Boolean
348
342
get() = MPVLib .getPropertyBoolean(" pause" )
349
343
set(paused) = MPVLib .setPropertyBoolean(" pause" , paused)
344
+ val playlistCount: Int
345
+ get() = MPVLib .getPropertyInt(" playlist-count" ) ? : 0
350
346
val isIdling: Boolean
351
347
get() = MPVLib .getPropertyBoolean(" idle-active" )
352
348
val eofReached: Boolean
@@ -502,6 +498,10 @@ class MPVPlayer(private val context: Application) : SurfaceHolder.Callback, MPVL
502
498
MPVLib .command(arrayOf(" loadfile" , filePath))
503
499
}
504
500
501
+ fun playlistPrev () {
502
+ MPVLib .command(arrayOf(" playlist-prev" ))
503
+ }
504
+
505
505
fun stop () {
506
506
MPVLib .command(arrayOf(" stop" ))
507
507
}
@@ -543,7 +543,8 @@ class MPVPlayer(private val context: Application) : SurfaceHolder.Callback, MPVL
543
543
544
544
fun screenshot (onSaveScreenshot : (File ) -> Unit ) {
545
545
val format = " jpg"
546
- val filename = " $filename -(${timePos.toDurationString(splitter = " -" )} )-${Random .nextInt()} "
546
+ val filename =
547
+ " $filename -(${timePos.toLong().toDurationString(splitter = " -" )} )-${Random .nextInt()} "
547
548
MPVLib .setOptionString(" screenshot-format" , format)
548
549
MPVLib .setOptionString(" screenshot-template" , filename)
549
550
MPVLib .command(arrayOf(" screenshot" ))
0 commit comments