Audio downloads when necessary
This commit is contained in:
@@ -22,9 +22,9 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
defaultProclamationID string = "f3d42354-3197-45e4-9b08-be447f14386d"
|
||||
proclamationPlayCount int = 10
|
||||
defaultProclamationPlayCount int = 1
|
||||
defaultProclamationID string = "f3d42354-3197-45e4-9b08-be447f14386d"
|
||||
proclamationPlayCount int = 20
|
||||
// defaultProclamationPlayCount int = 1
|
||||
)
|
||||
|
||||
// ProgressUpdate is sent over a channel as bytes are read from the network
|
||||
@@ -50,6 +50,47 @@ type ProgressReader struct {
|
||||
updates chan<- ProgressUpdate
|
||||
}
|
||||
|
||||
type ScrollerPage struct {
|
||||
Base
|
||||
|
||||
streams []proclamationStream
|
||||
streamIndex int
|
||||
|
||||
IsDownloadingAudio bool
|
||||
|
||||
lines *LineDeque
|
||||
lineHeight int32
|
||||
shader *shaderManager.Shader
|
||||
activePattern linePattern.LinePattern
|
||||
font *fontManager.FontEntry
|
||||
spaceWidth int32
|
||||
lineCtx *linePattern.LineRenderContext
|
||||
colorPattern *colorPattern.ColorPattern
|
||||
scrollOffset float32
|
||||
scrollY float32
|
||||
fontScale float32
|
||||
|
||||
// Reuse one GL texture per unique word.
|
||||
wordTextureCache map[string]StringItem
|
||||
|
||||
increment float32
|
||||
velocity float32
|
||||
|
||||
// Time-based velocity control
|
||||
velocityFloor float32
|
||||
velocityCeiling float32
|
||||
velocityStep float32
|
||||
velocityDelay float32
|
||||
velocityDirection int
|
||||
velocityTimer float32
|
||||
velocityState int
|
||||
autoVelocity bool
|
||||
hold float32
|
||||
|
||||
// Color palette settings
|
||||
useColorPalettes bool
|
||||
}
|
||||
|
||||
func (pr *ProgressReader) Read(p []byte) (int, error) {
|
||||
n, err := pr.Reader.Read(p)
|
||||
if n > 0 {
|
||||
@@ -214,45 +255,6 @@ func (d *LineDeque) Clear() {
|
||||
d.head, d.tail, d.count = 0, 0, 0
|
||||
}
|
||||
|
||||
type ScrollerPage struct {
|
||||
Base
|
||||
|
||||
streams []proclamationStream
|
||||
streamIndex int
|
||||
|
||||
lines *LineDeque
|
||||
lineHeight int32
|
||||
shader *shaderManager.Shader
|
||||
activePattern linePattern.LinePattern
|
||||
font *fontManager.FontEntry
|
||||
spaceWidth int32
|
||||
lineCtx *linePattern.LineRenderContext
|
||||
colorPattern *colorPattern.ColorPattern
|
||||
scrollOffset float32
|
||||
scrollY float32
|
||||
fontScale float32
|
||||
|
||||
// Reuse one GL texture per unique word.
|
||||
wordTextureCache map[string]StringItem
|
||||
|
||||
increment float32
|
||||
velocity float32
|
||||
|
||||
// Time-based velocity control
|
||||
velocityFloor float32
|
||||
velocityCeiling float32
|
||||
velocityStep float32
|
||||
velocityDelay float32
|
||||
velocityDirection int
|
||||
velocityTimer float32
|
||||
velocityState int
|
||||
autoVelocity bool
|
||||
hold float32
|
||||
|
||||
// Color palette settings
|
||||
useColorPalettes bool
|
||||
}
|
||||
|
||||
func (p *ScrollerPage) Init(ctx *PageCtx) error {
|
||||
p.increment = 100.0
|
||||
p.velocity = 800.0
|
||||
@@ -353,7 +355,7 @@ func (p *ScrollerPage) Init(ctx *PageCtx) error {
|
||||
_, err = os.Stat(selectedAudio.Path)
|
||||
if err != nil { // If err == nil, then the file was most likely not found
|
||||
url := "https://files.radiantwavetech.com/audio/" + filepath.Base(selectedAudio.Path)
|
||||
|
||||
p.IsDownloadingAudio = true
|
||||
updates := downloadFile(url, selectedAudio.Path)
|
||||
var downloadErr error
|
||||
for u := range updates {
|
||||
@@ -363,15 +365,16 @@ func (p *ScrollerPage) Init(ctx *PageCtx) error {
|
||||
}
|
||||
if u.Total > 0 {
|
||||
pct := float64(u.Read) / float64(u.Total) * 100
|
||||
fmt.Printf("\rDownloaded %d / %d bytes (%.1f%%)", u.Read, u.Total, pct)
|
||||
fmt.Printf("\rDownloaded %d / %d bytes (%.1f%%)\n", u.Read, u.Total, pct)
|
||||
} else {
|
||||
fmt.Printf("\rDownloaded %d bytes", u.Read)
|
||||
fmt.Printf("\rDownloaded %d bytes\n", u.Read)
|
||||
}
|
||||
if u.Done {
|
||||
fmt.Println()
|
||||
}
|
||||
}
|
||||
if downloadErr != nil {
|
||||
p.IsDownloadingAudio = false
|
||||
return fmt.Errorf("failed to downoad audio file: %v", downloadErr)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user