Better stringification of play times longer than 1 hr
This commit is contained in:
@@ -548,8 +548,8 @@ func (a *NowPlayingPage) formatStatusLine() {
|
|||||||
if state != "Stopped" {
|
if state != "Stopped" {
|
||||||
trackNum = a.pm.NowPlayingIndex() + 1
|
trackNum = a.pm.NowPlayingIndex() + 1
|
||||||
statusSuffix = fmt.Sprintf(" %s/%s",
|
statusSuffix = fmt.Sprintf(" %s/%s",
|
||||||
util.SecondsToTimeString(playerStats.TimePos),
|
util.SecondsToMMSS(playerStats.TimePos),
|
||||||
util.SecondsToTimeString(dur))
|
util.SecondsToMMSS(dur))
|
||||||
}
|
}
|
||||||
status := fmt.Sprintf("%s (%d/%d)%s", state, trackNum,
|
status := fmt.Sprintf("%s (%d/%d)%s", state, trackNum,
|
||||||
len(a.queue), statusSuffix)
|
len(a.queue), statusSuffix)
|
||||||
|
|||||||
+37
-1
@@ -32,7 +32,7 @@ func MakeOpaque(c color.Color) color.Color {
|
|||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func SecondsToTimeString(s float64) string {
|
func SecondsToMMSS(s float64) string {
|
||||||
if s < 0 {
|
if s < 0 {
|
||||||
s = 0
|
s = 0
|
||||||
}
|
}
|
||||||
@@ -43,6 +43,42 @@ func SecondsToTimeString(s float64) string {
|
|||||||
return fmt.Sprintf("%d:%02d", min, sec)
|
return fmt.Sprintf("%d:%02d", min, sec)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SecondsToTimeString(s float64) string {
|
||||||
|
if s < 3600 /*1 hour*/ {
|
||||||
|
return SecondsToMMSS(s)
|
||||||
|
}
|
||||||
|
sec := int64(s)
|
||||||
|
days := sec / 86400
|
||||||
|
sec -= days * 86400
|
||||||
|
hr := sec / 3600
|
||||||
|
sec -= hr * 3600
|
||||||
|
min := sec / 60
|
||||||
|
sec -= min * 60
|
||||||
|
|
||||||
|
var str string
|
||||||
|
if days > 0 {
|
||||||
|
daysStr := "days"
|
||||||
|
if days == 1 {
|
||||||
|
daysStr = "day"
|
||||||
|
}
|
||||||
|
str = fmt.Sprintf("%d %s ", days, daysStr)
|
||||||
|
}
|
||||||
|
if hr > 0 {
|
||||||
|
hrStr := "hrs"
|
||||||
|
if hr == 1 {
|
||||||
|
hrStr = "hr"
|
||||||
|
}
|
||||||
|
str += fmt.Sprintf("%d %s ", hr, hrStr)
|
||||||
|
}
|
||||||
|
if min > 0 {
|
||||||
|
str += fmt.Sprintf("%d min ", min)
|
||||||
|
}
|
||||||
|
if sec > 0 {
|
||||||
|
str += fmt.Sprintf("%d sec ", sec)
|
||||||
|
}
|
||||||
|
return str[:len(str)-1]
|
||||||
|
}
|
||||||
|
|
||||||
func BytesToSizeString(bytes int64) string {
|
func BytesToSizeString(bytes int64) string {
|
||||||
var num float64
|
var num float64
|
||||||
var suffix string
|
var suffix string
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package util
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestSecondsToTimeString(t *testing.T) {
|
||||||
|
inputs := []float64{
|
||||||
|
57.2,
|
||||||
|
3360,
|
||||||
|
4800,
|
||||||
|
4812,
|
||||||
|
86401,
|
||||||
|
}
|
||||||
|
outputs := []string{
|
||||||
|
"0:57",
|
||||||
|
"56:00",
|
||||||
|
"1 hr 20 min",
|
||||||
|
"1 hr 20 min 12 sec",
|
||||||
|
"1 day 1 sec",
|
||||||
|
}
|
||||||
|
for i, input := range inputs {
|
||||||
|
if s := SecondsToTimeString(input); s != outputs[i] {
|
||||||
|
t.Errorf("got %s, want %s", s, outputs[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -115,15 +115,15 @@ func NewPlayerControls() *PlayerControls {
|
|||||||
|
|
||||||
pc.slider = NewTrackPosSlider()
|
pc.slider = NewTrackPosSlider()
|
||||||
pc.slider.Disable()
|
pc.slider.Disable()
|
||||||
pc.curTimeLabel = NewLabelMinSize(util.SecondsToTimeString(0), 55)
|
pc.curTimeLabel = NewLabelMinSize(util.SecondsToMMSS(0), 55)
|
||||||
pc.curTimeLabel.Alignment = fyne.TextAlignTrailing
|
pc.curTimeLabel.Alignment = fyne.TextAlignTrailing
|
||||||
pc.totalTimeLabel = NewLabelMinSize(util.SecondsToTimeString(0), 55)
|
pc.totalTimeLabel = NewLabelMinSize(util.SecondsToMMSS(0), 55)
|
||||||
pc.totalTimeLabel.Alignment = fyne.TextAlignTrailing
|
pc.totalTimeLabel.Alignment = fyne.TextAlignTrailing
|
||||||
|
|
||||||
pc.slider.OnChanged = func(f float64) {
|
pc.slider.OnChanged = func(f float64) {
|
||||||
if pc.slider.IsDragging() {
|
if pc.slider.IsDragging() {
|
||||||
time := f * pc.totalTime
|
time := f * pc.totalTime
|
||||||
pc.curTimeLabel.SetText(util.SecondsToTimeString(time))
|
pc.curTimeLabel.SetText(util.SecondsToMMSS(time))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,7 +178,7 @@ func (pc *PlayerControls) UpdatePlayTime(curTime, totalTime float64) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
updated := false
|
updated := false
|
||||||
tt := util.SecondsToTimeString(totalTime)
|
tt := util.SecondsToMMSS(totalTime)
|
||||||
if tt != pc.totalTimeLabel.Text {
|
if tt != pc.totalTimeLabel.Text {
|
||||||
pc.totalTimeLabel.SetText(tt)
|
pc.totalTimeLabel.SetText(tt)
|
||||||
updated = true
|
updated = true
|
||||||
@@ -189,7 +189,7 @@ func (pc *PlayerControls) UpdatePlayTime(curTime, totalTime float64) {
|
|||||||
pc.slider.Disable()
|
pc.slider.Disable()
|
||||||
}
|
}
|
||||||
if !pc.slider.IsDragging() {
|
if !pc.slider.IsDragging() {
|
||||||
ct := util.SecondsToTimeString(curTime)
|
ct := util.SecondsToMMSS(curTime)
|
||||||
if ct != pc.curTimeLabel.Text {
|
if ct != pc.curTimeLabel.Text {
|
||||||
pc.curTimeLabel.SetText(ct)
|
pc.curTimeLabel.SetText(ct)
|
||||||
updated = true
|
updated = true
|
||||||
|
|||||||
@@ -475,7 +475,7 @@ func (p *PlayQueueListRow) Update(tm *util.TrackListModel, rowNum int) {
|
|||||||
p.trackID = meta.ID
|
p.trackID = meta.ID
|
||||||
p.title.Text = meta.Name
|
p.title.Text = meta.Name
|
||||||
p.artist.BuildSegments(meta.Artists, meta.ArtistIDs)
|
p.artist.BuildSegments(meta.Artists, meta.ArtistIDs)
|
||||||
p.time.Text = util.SecondsToTimeString(float64(meta.Duration))
|
p.time.Text = util.SecondsToMMSS(float64(meta.Duration))
|
||||||
changed = true
|
changed = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -266,7 +266,7 @@ func (t *tracklistRowBase) Update(tm *util.TrackListModel, rowNum int) {
|
|||||||
t.name.Segments[0].(*widget.TextSegment).Text = tr.Title
|
t.name.Segments[0].(*widget.TextSegment).Text = tr.Title
|
||||||
t.artist.BuildSegments(tr.ArtistNames, tr.ArtistIDs)
|
t.artist.BuildSegments(tr.ArtistNames, tr.ArtistIDs)
|
||||||
t.album.BuildSegments([]string{tr.Album}, []string{tr.AlbumID})
|
t.album.BuildSegments([]string{tr.Album}, []string{tr.AlbumID})
|
||||||
t.dur.Text = util.SecondsToTimeString(float64(tr.Duration))
|
t.dur.Text = util.SecondsToMMSS(float64(tr.Duration))
|
||||||
t.year.Text = strconv.Itoa(tr.Year)
|
t.year.Text = strconv.Itoa(tr.Year)
|
||||||
t.plays.Text = strconv.Itoa(int(tr.PlayCount))
|
t.plays.Text = strconv.Itoa(int(tr.PlayCount))
|
||||||
t.comment.Text = tr.Comment
|
t.comment.Text = tr.Comment
|
||||||
|
|||||||
Reference in New Issue
Block a user