Skip to content

Commit

Permalink
修复:视频的时间大于24小时会报错,不能播放字幕,不知道怎么回事,上一次的修改只提交了重命名,函数内的修改丢失了(#44)。
Browse files Browse the repository at this point in the history
  • Loading branch information
tangshimin committed Jan 4, 2024
1 parent ba9dfa9 commit 0affd17
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
5 changes: 2 additions & 3 deletions src/jvmMain/kotlin/player/MediaPlayerComponent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import com.matthewn4444.ebml.UnSupportSubtitlesException
import com.matthewn4444.ebml.subtitles.SRTSubtitles
import com.matthewn4444.ebml.subtitles.SSASubtitles
import com.sun.jna.NativeLibrary
import com.sun.jna.Platform.isLinux
import data.Caption
import org.mozilla.universalchardet.UniversalDetector
import state.getResourcesFile
Expand Down Expand Up @@ -302,8 +301,8 @@ fun parseSubtitles(subtitlesPath: String):List<PlayerCaption>{
content = removeItalicSymbol(content)
content = replaceNewLine(content)
val newCaption = PlayerCaption(
start = parseTime2(caption.start.getTime("hh:mm:ss.ms")),
end = parseTime2(caption.end.getTime("hh:mm:ss.ms")),
start = convertTimeToMilliseconds(caption.start.getTime("hh:mm:ss.ms")),
end = convertTimeToMilliseconds(caption.end.getTime("hh:mm:ss.ms")),
content = content
)
if (caption.content.length > maxLength) {
Expand Down
30 changes: 17 additions & 13 deletions src/jvmMain/kotlin/player/Play.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import uk.co.caprica.vlcj.player.component.CallbackMediaPlayerComponent
import uk.co.caprica.vlcj.player.component.EmbeddedMediaPlayerComponent
import java.awt.*
import java.awt.event.*
import java.time.LocalTime
import java.time.format.DateTimeFormatter
import javax.swing.JFrame
import javax.swing.JPanel

Expand Down Expand Up @@ -424,21 +422,27 @@ fun play(
* 转换时间为秒
*/
fun convertTimeToSeconds(time:String):Double{
var duration = LocalTime.parse(time, DateTimeFormatter.ofPattern("HH:mm:ss.SSS")).toNanoOfDay().toDouble()
duration = duration.div(1000_000_000)
return duration
val parts = time.split(":")
val hours = parts[0].toLong()
val minutes = parts[1].toLong()
val seconds = parts[2].toDouble()

val totalSeconds = hours * 3600 + minutes * 60 + seconds
return totalSeconds
}

/**
* 解析时间,返回毫秒
* 转换时间为毫秒
*/
fun parseTime2(time:String):Long{
val millis = time.substringAfter(".").toLong()
val list = time.substringBefore(".").split(":")
val hours = list[0].toLong()
val minutes = list[1].toLong()
val second = list[2].toLong()
return (hours * 3600 + minutes * 60 + second) * 1000 + millis
fun convertTimeToMilliseconds(time:String):Long{
val parts = time.split(":")
val hours = parts[0].toLong()
val minutes = parts[1].toLong()
val seconds = parts[2].substringBefore(".").toLong()
val milliseconds = parts[2].substringAfter(".").toLong()

val totalMilliseconds = ((hours * 3600 + minutes * 60 + seconds) * 1000) + milliseconds
return totalMilliseconds
}


Expand Down

0 comments on commit 0affd17

Please sign in to comment.