Skip to content

Commit

Permalink
[bugfix]<play>: fix file fd leaks (#17)
Browse files Browse the repository at this point in the history
Signed-off-by: o98k-ok <hggend@gmail.com>
  • Loading branch information
o98k-ok committed Mar 13, 2024
1 parent 2218314 commit a6a53b5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/music/music.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Music struct {
PauseTrigger func()
SeekTrigger func(int) error
DurationCallback func() int
Close func() error
PositionCallback func() int
}

Expand Down
7 changes: 7 additions & 0 deletions internal/player/play.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ func (vp *VoicePlayer) Run() error {
if vp.PlayingQueue.Size() == 0 && vp.CurrentElem != nil {
// avoid stream conflict
// time.Sleep(time.Millisecond * 100)
// clear last song file
if vp.CurrentElem != nil {
fn := vp.CurrentElem.Value.(*music.Music).Close
if fn != nil {
fn()
}
}
vp.CurrentElem = pkg.NextForward(vp.PlayList, vp.CurrentElem)
if vp.CurrentElem != nil {
vp.PlayingQueue.Add(vp.CurrentElem)
Expand Down
1 change: 1 addition & 0 deletions internal/player/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func (q *StreamerQueue) Add(elem *list.Element) {
data.DurationCallback = streamer.Len
data.PositionCallback = streamer.Position
data.SampleRate = format.SampleRate
data.Close = streamer.Close

q.streamers = append(q.streamers, NewTask(elem, c2))
}
Expand Down

0 comments on commit a6a53b5

Please sign in to comment.