MCPcopy Index your code
hub / github.com/g3n/engine / Play

Method Play

audio/player.go:96–142  ·  view source on GitHub ↗

Play starts playing this player

()

Source from the content-addressed store, hash-verified

94
95// Play starts playing this player
96func (p *Player) Play() error {
97
98 state := p.State()
99 // Already playing, nothing to do
100 if state == al.Playing {
101 return nil
102 }
103
104 // If paused, goroutine should be running, just starts playing
105 if state == al.Paused {
106 al.SourcePlay(p.source)
107 return nil
108 }
109
110 // Inactive or Stopped state
111 if state == al.Initial || state == al.Stopped {
112
113 // Sets file pointer to the beginning
114 err := p.af.Seek(0)
115 if err != nil {
116 return err
117 }
118
119 // Fill buffers with decoded data
120 for i := 0; i < playerBufferCount; i++ {
121 err = p.fillBuffer(p.buffers[i])
122 if err != nil {
123 if err != io.EOF {
124 return err
125 }
126 break
127 }
128 }
129 p.nextBuf = 0
130
131 // Clear previous goroutine response channel
132 select {
133 case _ = <-p.gchan:
134 default:
135 }
136 // Starts playing and starts goroutine to fill buffers
137 al.SourcePlay(p.source)
138 go p.run()
139 return nil
140 }
141 return nil
142}
143
144// Pause sets the player in the pause state
145func (p *Player) Pause() {

Callers

nothing calls this directly

Calls 5

StateMethod · 0.95
fillBufferMethod · 0.95
runMethod · 0.95
SourcePlayFunction · 0.92
SeekMethod · 0.80

Tested by

no test coverage detected