summaryrefslogtreecommitdiff
path: root/internal/gui/audio_player.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-01-21 21:43:40 +0200
committerPaul Buetow <paul@buetow.org>2026-01-21 21:43:40 +0200
commit8a4b935792c50101cf65b36e44f376c90c2d08c1 (patch)
tree2a8288e935fe89738fbc1243253bb638dc2620a8 /internal/gui/audio_player.go
parent2bd22f79f739136a7d30cf156979e2f2b23b7c65 (diff)
improve: better audio player UI and debugging for bg-bg cards
- Add debug logging to navigation.go to diagnose audio file loading issues Prints paths being checked and whether files are found - Improve AudioPlayer UI for Bulgarian-Bulgarian cards: - Add labels showing 'Front' and 'Back' for bg-bg audio buttons - Labels only show when audio files are actually loaded - Better visual distinction between the two playable audios - Reorganized button layout with VBox for cleaner appearance - Track bg-bg state in AudioPlayer (isBgBg field) - Automatically set when back audio file is loaded - Used to determine when to show labels This makes it clearer that Bulgarian-Bulgarian cards have two independently playable audio outputs, and helps debug why audio isn't being loaded.
Diffstat (limited to 'internal/gui/audio_player.go')
-rw-r--r--internal/gui/audio_player.go116
1 files changed, 109 insertions, 7 deletions
diff --git a/internal/gui/audio_player.go b/internal/gui/audio_player.go
index c0b3a0d..f9d0ad7 100644
--- a/internal/gui/audio_player.go
+++ b/internal/gui/audio_player.go
@@ -21,13 +21,18 @@ import (
type AudioPlayer struct {
widget.BaseWidget
- container *fyne.Container
- playButton *ttwidget.Button
- stopButton *ttwidget.Button
- statusLabel *widget.Label
- phoneticLabel *widget.Label
+ container *fyne.Container
+ playButton *ttwidget.Button
+ playButtonLabel *widget.Label // Label for front audio button
+ playBackButton *ttwidget.Button // Play back audio for bg-bg cards
+ playBackLabel *widget.Label // Label for back audio button
+ stopButton *ttwidget.Button
+ statusLabel *widget.Label
+ phoneticLabel *widget.Label
audioFile string
+ audioFileBack string // Back audio file for bg-bg cards
+ isBgBg bool // Track if this is a bg-bg card
isPlaying bool
playCmd *exec.Cmd
voiceInfo string // Stores voice and speed info
@@ -41,6 +46,15 @@ func NewAudioPlayer() *AudioPlayer {
// Create controls (tooltips will be set later after tooltip layer is created)
p.playButton = ttwidget.NewButton("", p.onPlay)
p.playButton.Icon = theme.MediaPlayIcon()
+
+ p.playButtonLabel = widget.NewLabel("")
+ p.playButtonLabel.TextStyle = fyne.TextStyle{Bold: true}
+
+ p.playBackButton = ttwidget.NewButton("", p.onPlayBack)
+ p.playBackButton.Icon = theme.MediaSkipNextIcon()
+
+ p.playBackLabel = widget.NewLabel("")
+ p.playBackLabel.TextStyle = fyne.TextStyle{Bold: true}
p.stopButton = ttwidget.NewButton("", p.onStop)
p.stopButton.Icon = theme.MediaStopIcon()
@@ -56,11 +70,17 @@ func NewAudioPlayer() *AudioPlayer {
// Initially disable controls
p.playButton.Disable()
+ p.playBackButton.Disable()
+ p.playBackButton.Hide() // Only show for bg-bg cards
+ p.playBackLabel.Hide()
p.stopButton.Disable()
// Create main container with phonetic display
p.container = container.NewHBox(
- p.playButton,
+ container.NewVBox(
+ container.NewHBox(p.playButton, p.playButtonLabel),
+ container.NewHBox(p.playBackButton, p.playBackLabel),
+ ),
p.stopButton,
p.phoneticLabel,
layout.NewSpacer(),
@@ -108,6 +128,13 @@ func (p *AudioPlayer) SetAudioFile(audioFile string) {
p.voiceInfo = ""
}
+ // Update button label based on whether this is bg-bg
+ if p.isBgBg {
+ p.playButtonLabel.SetText("Front")
+ } else {
+ p.playButtonLabel.SetText("")
+ }
+
// Format status text with voice and speed info
statusText := fmt.Sprintf("Audio: %s%s", filepath.Base(audioFile), p.voiceInfo)
p.statusLabel.SetText(statusText)
@@ -128,16 +155,53 @@ func (p *AudioPlayer) SetAudioFile(audioFile string) {
}
}
+// SetBackAudioFile sets the back audio file for bg-bg cards
+func (p *AudioPlayer) SetBackAudioFile(audioFile string) {
+ p.audioFileBack = audioFile
+ if audioFile != "" {
+ p.isBgBg = true
+ p.playBackButton.Enable()
+ p.playBackButton.Show()
+ p.playBackLabel.SetText("Back")
+ p.playBackLabel.Show()
+ // Update front label now that we know it's bg-bg
+ p.playButtonLabel.SetText("Front")
+ } else {
+ p.isBgBg = false
+ p.playBackButton.Disable()
+ p.playBackButton.Hide()
+ p.playBackLabel.SetText("")
+ p.playBackLabel.Hide()
+ // Clear front label if not bg-bg
+ p.playButtonLabel.SetText("")
+ }
+ // Refresh container to update layout after show/hide
+ if p.container != nil {
+ p.container.Refresh()
+ }
+}
+
// Clear clears the audio player
func (p *AudioPlayer) Clear() {
- p.onStop() // Stop any playing audio
+ p.onStop()
p.audioFile = ""
+ p.audioFileBack = ""
+ p.isBgBg = false
p.isPlaying = false
p.voiceInfo = ""
p.playButton.Disable()
+ p.playBackButton.Disable()
+ p.playBackButton.Hide()
+ p.playButtonLabel.SetText("")
+ p.playBackLabel.SetText("")
+ p.playBackLabel.Hide()
p.stopButton.Disable()
p.statusLabel.SetText("No audio loaded")
p.phoneticLabel.SetText("")
+ // Refresh container to update layout after hiding back button
+ if p.container != nil {
+ p.container.Refresh()
+ }
}
// SetPhonetic sets the phonetic transcription text
@@ -179,6 +243,35 @@ func (p *AudioPlayer) onPlay() {
p.statusLabel.SetText(fmt.Sprintf("Playing: %s%s", filepath.Base(p.audioFile), p.voiceInfo))
}
+// onPlayBack handles back audio button click (for bg-bg cards)
+func (p *AudioPlayer) onPlayBack() {
+ if p.audioFileBack == "" {
+ return
+ }
+
+ if p.isPlaying {
+ p.onStop()
+ }
+
+ // Temporarily swap audio files to play the back audio
+ originalFile := p.audioFile
+ p.audioFile = p.audioFileBack
+
+ if err := p.startPlayback(); err != nil {
+ p.statusLabel.SetText(fmt.Sprintf("Error: %v", err))
+ p.audioFile = originalFile
+ return
+ }
+
+ p.isPlaying = true
+ p.playButton.SetIcon(theme.MediaPauseIcon())
+ p.stopButton.Enable()
+ p.statusLabel.SetText(fmt.Sprintf("Playing back audio: %s", filepath.Base(p.audioFileBack)))
+
+ // Restore original file after playback starts
+ p.audioFile = originalFile
+}
+
// onStop handles stop button click
func (p *AudioPlayer) onStop() {
if p.playCmd != nil && p.playCmd.Process != nil {
@@ -201,6 +294,15 @@ func (p *AudioPlayer) Play() {
}
}
+// PlayBack triggers back audio playback (for bg-bg cards)
+func (p *AudioPlayer) PlayBack() {
+ if !p.playBackButton.Disabled() {
+ fyne.Do(func() {
+ p.onPlayBack()
+ })
+ }
+}
+
// startPlayback starts audio playback using platform-specific commands
func (p *AudioPlayer) startPlayback() error {
var cmd *exec.Cmd