mirror of
https://github.com/AynaLivePlayer/AynaLivePlayer.git
synced 2025-12-15 14:38:17 +08:00
finish config_basic.go
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"AynaLivePlayer/util"
|
||||
"github.com/aynakeya/go-mpv"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
const MODULE_PLAYER = "Player.Player"
|
||||
@@ -154,3 +155,32 @@ func (p *Player) ObserveProperty(property string, handler ...PropertyHandlerFunc
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type AudioDevice struct {
|
||||
Name string
|
||||
Description string
|
||||
}
|
||||
|
||||
// GetAudioDeviceList get output device for mpv
|
||||
// return format is []AudioDevice
|
||||
func (p *Player) GetAudioDeviceList() ([]AudioDevice, error) {
|
||||
p.l().Trace("getting audio device list for mpv")
|
||||
property, err := p.libmpv.GetProperty("audio-device-list", mpv.FORMAT_STRING)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dl := make([]AudioDevice, 0)
|
||||
gjson.Parse(property.(string)).ForEach(func(key, value gjson.Result) bool {
|
||||
dl = append(dl, AudioDevice{
|
||||
Name: value.Get("name").String(),
|
||||
Description: value.Get("description").String(),
|
||||
})
|
||||
return true
|
||||
})
|
||||
return dl, nil
|
||||
}
|
||||
|
||||
func (p *Player) SetAudioDevice(device string) error {
|
||||
p.l().Tracef("set audio device %s for mpv", device)
|
||||
return p.libmpv.SetPropertyString("audio-device", device)
|
||||
}
|
||||
|
||||
@@ -58,7 +58,14 @@ func (p *Playlist) Pop() *Media {
|
||||
return nil
|
||||
}
|
||||
p.Lock.Lock()
|
||||
media := p.Playlist[0]
|
||||
index := 0
|
||||
if p.Config.RandomNext {
|
||||
index = rand.Intn(p.Size())
|
||||
}
|
||||
media := p.Playlist[index]
|
||||
for i := index; i > 0; i-- {
|
||||
p.Playlist[i] = p.Playlist[i-1]
|
||||
}
|
||||
p.Playlist = p.Playlist[1:]
|
||||
p.Lock.Unlock()
|
||||
defer p.Handler.CallA(EventPlaylistUpdate, PlaylistUpdateEvent{Playlist: p})
|
||||
|
||||
Reference in New Issue
Block a user