Audio downloads when necessary
This commit is contained in:
@@ -23,8 +23,8 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
defaultProclamationID string = "f3d42354-3197-45e4-9b08-be447f14386d"
|
defaultProclamationID string = "f3d42354-3197-45e4-9b08-be447f14386d"
|
||||||
proclamationPlayCount int = 10
|
proclamationPlayCount int = 20
|
||||||
defaultProclamationPlayCount int = 1
|
// defaultProclamationPlayCount int = 1
|
||||||
)
|
)
|
||||||
|
|
||||||
// ProgressUpdate is sent over a channel as bytes are read from the network
|
// ProgressUpdate is sent over a channel as bytes are read from the network
|
||||||
@@ -50,6 +50,47 @@ type ProgressReader struct {
|
|||||||
updates chan<- ProgressUpdate
|
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) {
|
func (pr *ProgressReader) Read(p []byte) (int, error) {
|
||||||
n, err := pr.Reader.Read(p)
|
n, err := pr.Reader.Read(p)
|
||||||
if n > 0 {
|
if n > 0 {
|
||||||
@@ -214,45 +255,6 @@ func (d *LineDeque) Clear() {
|
|||||||
d.head, d.tail, d.count = 0, 0, 0
|
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 {
|
func (p *ScrollerPage) Init(ctx *PageCtx) error {
|
||||||
p.increment = 100.0
|
p.increment = 100.0
|
||||||
p.velocity = 800.0
|
p.velocity = 800.0
|
||||||
@@ -353,7 +355,7 @@ func (p *ScrollerPage) Init(ctx *PageCtx) error {
|
|||||||
_, err = os.Stat(selectedAudio.Path)
|
_, err = os.Stat(selectedAudio.Path)
|
||||||
if err != nil { // If err == nil, then the file was most likely not found
|
if err != nil { // If err == nil, then the file was most likely not found
|
||||||
url := "https://files.radiantwavetech.com/audio/" + filepath.Base(selectedAudio.Path)
|
url := "https://files.radiantwavetech.com/audio/" + filepath.Base(selectedAudio.Path)
|
||||||
|
p.IsDownloadingAudio = true
|
||||||
updates := downloadFile(url, selectedAudio.Path)
|
updates := downloadFile(url, selectedAudio.Path)
|
||||||
var downloadErr error
|
var downloadErr error
|
||||||
for u := range updates {
|
for u := range updates {
|
||||||
@@ -363,15 +365,16 @@ func (p *ScrollerPage) Init(ctx *PageCtx) error {
|
|||||||
}
|
}
|
||||||
if u.Total > 0 {
|
if u.Total > 0 {
|
||||||
pct := float64(u.Read) / float64(u.Total) * 100
|
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 {
|
} else {
|
||||||
fmt.Printf("\rDownloaded %d bytes", u.Read)
|
fmt.Printf("\rDownloaded %d bytes\n", u.Read)
|
||||||
}
|
}
|
||||||
if u.Done {
|
if u.Done {
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if downloadErr != nil {
|
if downloadErr != nil {
|
||||||
|
p.IsDownloadingAudio = false
|
||||||
return fmt.Errorf("failed to downoad audio file: %v", downloadErr)
|
return fmt.Errorf("failed to downoad audio file: %v", downloadErr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user