MCPcopy
hub / github.com/EngoEngine/engo / newPlayer

Function newPlayer

common/audio_player.go:58–86  ·  view source on GitHub ↗
(src convert.ReadSeekCloser, url string)

Source from the content-addressed store, hash-verified

56}
57
58func newPlayer(src convert.ReadSeekCloser, url string) (*Player, error) {
59 p := &Player{
60 src: src,
61 url: url,
62 sampleRate: SampleRate,
63 buf: []byte{},
64 volume: 1,
65 closeCh: make(chan struct{}),
66 closedCh: make(chan struct{}),
67 readLoopEndedCh: make(chan struct{}),
68 seekCh: make(chan seekArgs),
69 seekedCh: make(chan error),
70 proceedCh: make(chan []int16),
71 proceededCh: make(chan proceededValues),
72 syncCh: make(chan func()),
73 }
74 // Get the current position of the source.
75 pos, err := p.src.Seek(0, io.SeekCurrent)
76 if err != nil {
77 return nil, err
78 }
79 p.pos = pos
80 runtime.SetFinalizer(p, (*Player).Close)
81
82 go func() {
83 p.readLoop()
84 }()
85 return p, nil
86}
87
88// Close removes the player from the audio system's players, which are currently playing players.
89// it then finalizes and frees the data from the player. Do not use a player after it has been

Callers 1

LoadMethod · 0.85

Calls 2

readLoopMethod · 0.95
SeekMethod · 0.45

Tested by

no test coverage detected