File tree Expand file tree Collapse file tree
androidMain/kotlin/io/github/kdroidfilter/composemediaplayer
commonMain/kotlin/io/github/kdroidfilter/composemediaplayer
iosMain/kotlin/io/github/kdroidfilter/composemediaplayer
jvmMain/kotlin/io/github/kdroidfilter/composemediaplayer
webMain/kotlin/io/github/kdroidfilter/composemediaplayer Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -58,6 +58,7 @@ actual fun createVideoPlayerState(audioMode: AudioMode): VideoPlayerState =
5858 positionText = " 00:00" ,
5959 durationText = " 00:00" ,
6060 currentTime = 0.0 ,
61+ duration = 0.0 ,
6162 isFullscreen = false ,
6263 aspectRatio = 16f / 9f ,
6364 error =
@@ -267,6 +268,7 @@ open class DefaultVideoPlayerState(
267268 override val positionText: String get() = formatTime(_currentTime )
268269 override val durationText: String get() = formatTime(_duration )
269270 override val currentTime: Double get() = _currentTime
271+ override val duration: Double get() = _duration
270272
271273 override val isPipSupported: Boolean
272274 get() {
Original file line number Diff line number Diff line change @@ -73,6 +73,11 @@ interface VideoPlayerState {
7373 */
7474 val durationText: String
7575 val currentTime: Double
76+
77+ /* *
78+ * Returns the total duration of the media in seconds.
79+ */
80+ val duration: Double
7681 var isFullscreen: Boolean
7782 val aspectRatio: Float
7883
@@ -190,6 +195,7 @@ data class PreviewableVideoPlayerState(
190195 override val positionText : String = " 00:05" ,
191196 override val durationText : String = " 00:10" ,
192197 override val currentTime : Double = 5000.0 ,
198+ override val duration : Double = 10.0 ,
193199 override var isFullscreen : Boolean = false ,
194200 override val aspectRatio : Float = 1.7f ,
195201 override val error : VideoPlayerError ? = null ,
Original file line number Diff line number Diff line change @@ -169,6 +169,7 @@ open class DefaultVideoPlayerState(
169169 private var _currentTime : Double = 0.0
170170 private var _duration : Double = 0.0
171171 override val currentTime: Double get() = _currentTime
172+ override val duration: Double get() = _duration
172173
173174 // Observable video aspect ratio (default to 16:9)
174175 private var _videoAspectRatio by mutableStateOf(16.0 / 9.0 )
Original file line number Diff line number Diff line change @@ -103,6 +103,7 @@ open class DefaultVideoPlayerState : VideoPlayerState {
103103 override val positionText: String get() = delegate.positionText
104104 override val durationText: String get() = delegate.durationText
105105 override val currentTime: Double get() = delegate.currentTime
106+ override val duration: Double get() = delegate.duration
106107
107108 override fun openUri (
108109 uri : String ,
Original file line number Diff line number Diff line change @@ -112,6 +112,12 @@ class LinuxVideoPlayerState : VideoPlayerState {
112112 if (hasMedia) getPositionSafely() else 0.0
113113 }
114114
115+ override val duration: Double
116+ get() =
117+ runBlocking {
118+ if (hasMedia) getDurationSafely() else 0.0
119+ }
120+
115121 private val _aspectRatio = mutableStateOf(16f / 9f )
116122 override val aspectRatio: Float get() = _aspectRatio .value
117123
Original file line number Diff line number Diff line change @@ -110,6 +110,12 @@ class MacVideoPlayerState : VideoPlayerState {
110110 if (hasMedia) getPositionSafely() else 0.0
111111 }
112112
113+ override val duration: Double
114+ get() =
115+ runBlocking {
116+ if (hasMedia) getDurationSafely() else 0.0
117+ }
118+
113119 // Non-blocking aspect ratio property
114120 private val _aspectRatio = mutableStateOf(16f / 9f )
115121 override val aspectRatio: Float get() = _aspectRatio .value
Original file line number Diff line number Diff line change @@ -223,6 +223,7 @@ class WindowsVideoPlayerState : VideoPlayerState {
223223 override val positionText: String get() = formatTime(_currentTime )
224224 override val durationText: String get() = formatTime(_duration )
225225 override val currentTime: Double get() = _currentTime
226+ override val duration: Double get() = _duration
226227 private var errorMessage: String? by mutableStateOf(null )
227228
228229 // Fullscreen state
Original file line number Diff line number Diff line change @@ -126,6 +126,7 @@ open class DefaultVideoPlayerState : VideoPlayerState {
126126 // Current time of the media in seconds
127127 private var _currentTime : Double = 0.0
128128 override val currentTime: Double get() = _currentTime
129+ override val duration: Double get() = _currentDuration .toDouble()
129130
130131 // Job for handling seek operations
131132 internal var seekJob: Job ? = null
You can’t perform that action at this time.
0 commit comments