Major improvements to UnifiedPlayer: 1. GetFrameImage() now works when paused for responsive UI updates 2. Play() method properly starts FFmpeg process 3. Frame display loop runs continuously for smooth video display 4. Disabled audio temporarily to fix video playback fundamentals 5. Simplified FFmpeg command to focus on video stream only Player now: - Generates video frames correctly - Shows video when paused - Has responsive progress tracking - Starts playback properly Next steps: Re-enable audio playback once video is stable
69 lines
1.6 KiB
Go
69 lines
1.6 KiB
Go
package cache
|
|
|
|
import (
|
|
"image/color"
|
|
"time"
|
|
|
|
"fyne.io/fyne/v2"
|
|
"fyne.io/fyne/v2/internal/async"
|
|
)
|
|
|
|
var fontSizeCache async.Map[fontSizeEntry, *fontMetric]
|
|
|
|
type fontMetric struct {
|
|
expiringCache
|
|
size fyne.Size
|
|
baseLine float32
|
|
}
|
|
|
|
type fontSizeEntry struct {
|
|
Text string
|
|
Size float32
|
|
Style fyne.TextStyle
|
|
Source string
|
|
}
|
|
|
|
type FontCacheEntry struct {
|
|
fontSizeEntry
|
|
|
|
Canvas fyne.Canvas
|
|
Color color.Color
|
|
}
|
|
|
|
// GetFontMetrics looks up a calculated size and baseline required for the specified text parameters.
|
|
func GetFontMetrics(text string, fontSize float32, style fyne.TextStyle, source fyne.Resource) (size fyne.Size, base float32) {
|
|
name := ""
|
|
if source != nil {
|
|
name = source.Name()
|
|
}
|
|
ent := fontSizeEntry{text, fontSize, style, name}
|
|
ret, ok := fontSizeCache.Load(ent)
|
|
if !ok {
|
|
return fyne.Size{Width: 0, Height: 0}, 0
|
|
}
|
|
ret.setAlive()
|
|
return ret.size, ret.baseLine
|
|
}
|
|
|
|
// SetFontMetrics stores a calculated font size and baseline for parameters that were missing from the cache.
|
|
func SetFontMetrics(text string, fontSize float32, style fyne.TextStyle, source fyne.Resource, size fyne.Size, base float32) {
|
|
name := ""
|
|
if source != nil {
|
|
name = source.Name()
|
|
}
|
|
ent := fontSizeEntry{text, fontSize, style, name}
|
|
metric := &fontMetric{size: size, baseLine: base}
|
|
metric.setAlive()
|
|
fontSizeCache.Store(ent, metric)
|
|
}
|
|
|
|
// destroyExpiredFontMetrics destroys expired fontSizeCache entries
|
|
func destroyExpiredFontMetrics(now time.Time) {
|
|
fontSizeCache.Range(func(k fontSizeEntry, v *fontMetric) bool {
|
|
if v.isExpired(now) {
|
|
fontSizeCache.Delete(k)
|
|
}
|
|
return true
|
|
})
|
|
}
|