Skip to content

Commit

Permalink
fix: disable audio on web
Browse files Browse the repository at this point in the history
  • Loading branch information
gaoliveira21 committed Dec 23, 2023
1 parent c7d556f commit 2dfe353
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions core/audio/audio.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package audio

import (
"bytes"
"errors"
"io"
"os"

"github.com/gaoliveira21/chip8/core/http"
"github.com/hajimehoshi/ebiten/v2/audio"
"github.com/hajimehoshi/ebiten/v2/audio/mp3"
)
Expand All @@ -14,16 +13,6 @@ const sampleRate = 48000

type AudioPlayer = *audio.Player

func readFromServer(mp3FilePath string) (io.Reader, error) {
b, err := http.ReadFile(mp3FilePath)

if err != nil {
return nil, err
}

return bytes.NewReader(b), nil
}

func readFromFS(mp3FilePath string) (io.Reader, error) {
r, err := os.Open(mp3FilePath)

Expand All @@ -41,11 +30,11 @@ func NewAudioPlayer(mp3FilePath string) (AudioPlayer, error) {
var err error

if execMode == "web" {
r, err = readFromServer(mp3FilePath)
} else {
r, err = readFromFS(mp3FilePath)
return nil, errors.New("audio unsuported on web")
}

r, err = readFromFS(mp3FilePath)

if err != nil {
return nil, err
}
Expand Down

0 comments on commit 2dfe353

Please sign in to comment.