starting audio player
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
package player
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/gopxl/beep/mp3"
|
||||
"github.com/gopxl/beep/speaker"
|
||||
)
|
||||
|
||||
type Player struct {
|
||||
ctx context.Context
|
||||
state PlayerState
|
||||
}
|
||||
|
||||
type PlayerState int
|
||||
|
||||
const (
|
||||
Playing PlayerState = iota
|
||||
Paused
|
||||
Stopped
|
||||
)
|
||||
|
||||
func NewPlayer() *Player {
|
||||
return &Player{}
|
||||
}
|
||||
|
||||
func (p *Player) Init(ctx context.Context) {
|
||||
p.ctx = ctx
|
||||
p.state = Stopped
|
||||
}
|
||||
|
||||
func (p *Player) ChangeState(desiredState PlayerState) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Player) Play() error {
|
||||
f, err := os.Open("test_data/music_library_test/03 anything.mp3")
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to open file %w", err)
|
||||
}
|
||||
|
||||
streamer, format, err := mp3.Decode(f)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to decode mp3 %w", err)
|
||||
}
|
||||
defer streamer.Close()
|
||||
|
||||
err = speaker.Init(format.SampleRate, format.SampleRate.N(time.Second/10))
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to initialize speaker %w", err)
|
||||
}
|
||||
speaker.Play(streamer)
|
||||
select {}
|
||||
return nil
|
||||
}
|
||||
@@ -46,6 +46,11 @@
|
||||
<label id="library-directory-label">No Library Directory Selected</label>
|
||||
<button onclick="dirPicker()">Choose Directory...</button>
|
||||
</section>
|
||||
<section>
|
||||
<button onclick="onPlayPauseButtonClick()">
|
||||
<img src="/src/assets/images/icons/music/play-solid.svg" id="playPauseButtonIcon"/>
|
||||
</button>
|
||||
</section>
|
||||
</main>
|
||||
<footer></footer>
|
||||
</body>
|
||||
|
||||
+18
-1
@@ -1,8 +1,10 @@
|
||||
import './pico.css';
|
||||
import { DirectoryPicker, GetLibraryDir } from '../wailsjs/go/main/App';
|
||||
import { DirectoryPicker, GetLibraryDir} from '../wailsjs/go/main/App';
|
||||
import { Play } from '../wailsjs/go/player/Player';
|
||||
|
||||
|
||||
let libraryDirectoryLabel = document.getElementById("library-directory-label");
|
||||
let playPauseButtonIcon = document.getElementById("playPauseButtonIcon");
|
||||
|
||||
GetLibraryDir().
|
||||
then((result) => {
|
||||
@@ -10,6 +12,21 @@ GetLibraryDir().
|
||||
window.updateLibraryDirLabel(result);
|
||||
}).catch((err) => { console.error(err) })
|
||||
|
||||
window.onPlayPauseButtonClick = function() {
|
||||
try {
|
||||
Play().then((result) => {
|
||||
console.log(result)
|
||||
playPauseButton.setAttribute("src", "/src/assets/images/icons/music/pause-solid.svg")
|
||||
}).catch((err) => {
|
||||
console.log("There is an error with playing")
|
||||
console.error(err);
|
||||
});
|
||||
}
|
||||
catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
window.dirPicker = function() {
|
||||
var dir;
|
||||
try {
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
import {context} from '../models';
|
||||
|
||||
export function Init(arg1:context.Context):Promise<void>;
|
||||
|
||||
export function Play():Promise<void>;
|
||||
Executable
+11
@@ -0,0 +1,11 @@
|
||||
// @ts-check
|
||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
|
||||
export function Init(arg1) {
|
||||
return window['go']['player']['Player']['Init'](arg1);
|
||||
}
|
||||
|
||||
export function Play() {
|
||||
return window['go']['player']['Player']['Play']();
|
||||
}
|
||||
@@ -4,14 +4,18 @@ go 1.23
|
||||
|
||||
require (
|
||||
github.com/BurntSushi/toml v1.5.0
|
||||
github.com/gopxl/beep v1.4.1
|
||||
github.com/wailsapp/wails/v2 v2.10.1
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/bep/debounce v1.2.1 // indirect
|
||||
github.com/ebitengine/oto/v3 v3.1.0 // indirect
|
||||
github.com/ebitengine/purego v0.7.1 // indirect
|
||||
github.com/go-ole/go-ole v1.3.0 // indirect
|
||||
github.com/godbus/dbus/v5 v5.1.0 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/hajimehoshi/go-mp3 v0.3.4 // indirect
|
||||
github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e // indirect
|
||||
github.com/labstack/echo/v4 v4.13.3 // indirect
|
||||
github.com/labstack/gommon v0.4.2 // indirect
|
||||
|
||||
@@ -4,12 +4,21 @@ github.com/bep/debounce v1.2.1 h1:v67fRdBA9UQu2NhLFXrSg0Brw7CexQekrBwDMM8bzeY=
|
||||
github.com/bep/debounce v1.2.1/go.mod h1:H8yggRPQKLUhUoqrJC1bO2xNya7vanpDl7xR3ISbCJ0=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/ebitengine/oto/v3 v3.1.0 h1:9tChG6rizyeR2w3vsygTTTVVJ9QMMyu00m2yBOCch6U=
|
||||
github.com/ebitengine/oto/v3 v3.1.0/go.mod h1:IK1QTnlfZK2GIB6ziyECm433hAdTaPpOsGMLhEyEGTg=
|
||||
github.com/ebitengine/purego v0.7.1 h1:6/55d26lG3o9VCZX8lping+bZcmShseiqlh2bnUDiPA=
|
||||
github.com/ebitengine/purego v0.7.1/go.mod h1:ah1In8AOtksoNK6yk5z1HTJeUkC1Ez4Wk2idgGslMwQ=
|
||||
github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE=
|
||||
github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78=
|
||||
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
|
||||
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/gopxl/beep v1.4.1 h1:WqNs9RsDAhG9M3khMyc1FaVY50dTdxG/6S6a3qsUHqE=
|
||||
github.com/gopxl/beep v1.4.1/go.mod h1:A1dmiUkuY8kxsvcNJNUBIEcchmiP6eUyCHSxpXl0YO0=
|
||||
github.com/hajimehoshi/go-mp3 v0.3.4 h1:NUP7pBYH8OguP4diaTZ9wJbUbk3tC0KlfzsEpWmYj68=
|
||||
github.com/hajimehoshi/go-mp3 v0.3.4/go.mod h1:fRtZraRFcWb0pu7ok0LqyFhCUrPeMsGRSVop0eemFmo=
|
||||
github.com/hajimehoshi/oto/v2 v2.3.1/go.mod h1:seWLbgHH7AyUMYKfKYT9pg7PhUu9/SisyJvNTT+ASQo=
|
||||
github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e h1:Q3+PugElBCf4PFpxhErSzU3/PY5sFL5Z6rfv4AbGAck=
|
||||
github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e/go.mod h1:alcuEEnZsY1WQsagKhZDsoPCRoOijYqhZvPwLG0kzVs=
|
||||
github.com/labstack/echo/v4 v4.13.3 h1:pwhpCPrTl5qry5HRdM5FwdXnhXSLSY+WE+YQSeCaafY=
|
||||
@@ -67,6 +76,7 @@ golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk=
|
||||
golang.org/x/sys v0.0.0-20200810151505-1b9f1253b3ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20220712014510-0a85c31ab51e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"yellowjacket/backend/config"
|
||||
"yellowjacket/backend/player"
|
||||
|
||||
"github.com/wailsapp/wails/v2"
|
||||
"github.com/wailsapp/wails/v2/pkg/logger"
|
||||
@@ -23,6 +24,7 @@ func main() {
|
||||
}
|
||||
|
||||
app := NewApp(config)
|
||||
player := player.NewPlayer()
|
||||
|
||||
// Create application with options
|
||||
err = wails.Run(&options.App{
|
||||
@@ -32,13 +34,15 @@ func main() {
|
||||
AssetServer: &assetserver.Options{
|
||||
Assets: assets,
|
||||
},
|
||||
LogLevel: logger.INFO,
|
||||
LogLevel: logger.TRACE,
|
||||
BackgroundColour: &options.RGBA{R: 27, G: 38, B: 54, A: 1},
|
||||
OnStartup: func(ctx context.Context) {
|
||||
app.startup(ctx)
|
||||
player.Init(ctx)
|
||||
},
|
||||
Bind: []interface{}{
|
||||
app,
|
||||
player,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user