Play starts playing this player
()
| 94 | |
| 95 | // Play starts playing this player |
| 96 | func (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 |
| 145 | func (p *Player) Pause() { |
nothing calls this directly
no test coverage detected