Skip to content

Commit

Permalink
seeking works
Browse files Browse the repository at this point in the history
testing complete, bump versions
  • Loading branch information
dondish committed Oct 15, 2019
1 parent 4e92b34 commit bf22323
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 33 deletions.
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ go 1.13
require (
github.com/bwmarrin/discordgo v0.19.0
github.com/dondish/lionPlayer/core v0.0.1
github.com/dondish/lionPlayer/webm v0.0.2 // indirect
github.com/dondish/lionPlayer/youtube v0.0.1-test1
github.com/dondish/lionPlayer/youtube v0.0.2
github.com/gorilla/websocket v1.4.1 // indirect
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 // indirect
golang.org/x/sys v0.0.0-20191010194322-b09406accb47 // indirect
Expand Down
14 changes: 7 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func main() {
func ready(s *discordgo.Session, event *discordgo.Ready) {

// Set the playing status.
s.UpdateStatus(0, "!airhorn")
s.UpdateStatus(0, "Playing music using Go only!")
}

// This function will be called (due to AddHandler above) every time a new
Expand All @@ -111,7 +111,7 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
}

// check if the message is "!airhorn"
if strings.HasPrefix(m.Content, "!play") && track == nil {
if strings.HasPrefix(m.Content, "y!play") && track == nil {
// Find the channel that the message came from.
c, err := s.State.Channel(m.ChannelID)
if err != nil {
Expand Down Expand Up @@ -153,11 +153,11 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
return
}
}
} else if strings.HasPrefix(m.Content, "!stop") {
} else if strings.HasPrefix(m.Content, "y!stop") {
if track != nil {
track.Close()
}
} else if strings.HasPrefix(m.Content, "!seek") {
} else if strings.HasPrefix(m.Content, "y!seek") {
// Find the channel that the message came from.
c, err := s.State.Channel(m.ChannelID)
if err != nil {
Expand Down Expand Up @@ -196,15 +196,15 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
}
ms := time.Duration(hour)*time.Hour + time.Duration(minute)*time.Minute + time.Duration(second)*time.Second
_ = track.Seek(ms)
} else if strings.HasPrefix(m.Content, "!pause") {
} else if strings.HasPrefix(m.Content, "y!pause") {
if track != nil {
track.Pause(true)
}
} else if strings.HasPrefix(m.Content, "!unpause") || strings.HasPrefix(m.Content, "!resume") {
} else if strings.HasPrefix(m.Content, "y!unpause") || strings.HasPrefix(m.Content, "!resume") {
if track != nil {
track.Pause(false)
}
} else if strings.HasPrefix(m.Content, "!position") {
} else if strings.HasPrefix(m.Content, "y!position") {
c, err := s.State.Channel(m.ChannelID)
if err != nil {
// Could not find channel.
Expand Down
28 changes: 5 additions & 23 deletions webm/track.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ func (t Track) internalSeek(duration time.Duration) error {
if t.cues == 0 {
return errors.New("seeks are not supported in streams")
}
curr, err := t.segment.Seek(0, 1)
_, err = t.segment.Seek(t.cues, 0)
_, err := t.segment.Seek(t.cues, 0)
cues, err := t.segment.Next()
if err != nil {
return err
Expand All @@ -132,33 +131,17 @@ func (t Track) internalSeek(duration time.Duration) error {
return err
}

if time.Duration(cuepoint.Time)*time.Millisecond >= duration { // Found the cuepoint that passed the duration given
log.Println("bypassed time", pos, duration)
_, err = t.segment.Seek(t.segment.Offset, 0)
if err != nil {
return err
}
sh, err := t.segment.Next()
if err != nil {
return err
}
if pos > 0 {
_, err := t.segment.Seek(sh.Offset+int64(pos), 0) // return the last
return err
} else {
_, err = t.segment.Seek(sh.Offset+curr, 0)
return err
}
if time.Duration(cuepoint.Time)*time.Millisecond > duration { // Found the cuepoint that passed the duration given
_, err = t.segment.Seek(t.segment.Offset+12+int64(pos), 0)
return err
}
for _, track := range cuepoint.Positions {
if track.Track == t.trackId {
log.Println("found the track")
log.Println(track.ClusterPosition)
pos = track.ClusterPosition
}
}
}
_, err = t.segment.Seek(t.segment.Offset+int64(pos), 0) // last cluster
_, err = t.segment.Seek(t.segment.Offset+12+int64(pos), 0) // last cluster
return err
}

Expand Down Expand Up @@ -329,7 +312,6 @@ func (t Track) Play() {
}
}
if seek == shutdown {
log.Println("shutting down")
break
}
if seek != badTC {
Expand Down
2 changes: 1 addition & 1 deletion youtube/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ go 1.13

require github.com/dondish/lionPlayer/core v0.0.1

require github.com/dondish/lionPlayer/webm v0.0.3-test1
require github.com/dondish/lionPlayer/webm v0.0.4

require github.com/jeffallen/seekinghttp v0.0.0-20171214161738-f41d11cb25b7

0 comments on commit bf22323

Please sign in to comment.