Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ func main() {
// Format of the source. go-mp3's format is signed 16bit integers.
op.Format = oto.FormatSignedInt16LE

// Remember that you should **not** create more than one context
// Remember that you should **not** create more than one context.
// Calling oto.NewContext more than once returns an error: reuse the context for all your players.
otoCtx, readyChan, err := oto.NewContext(op)
if err != nil {
panic("oto.NewContext failed: " + err.Error())
Expand Down
2 changes: 1 addition & 1 deletion context.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func NewContext(options *NewContextOptions) (*Context, chan struct{}, error) {
defer contextCreationMutex.Unlock()

if contextCreated {
return nil, nil, fmt.Errorf("oto: context is already created")
return nil, nil, fmt.Errorf("oto: context is already created (NewContext can be called only once per process; reuse the existing context instead)")
}
contextCreated = true

Expand Down
11 changes: 11 additions & 0 deletions oto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,14 @@ func TestSetBufferSize(t *testing.T) {
}
}
}

func TestNewContextAfterContextCreated(t *testing.T) {
// TestMain already created the context, so this call must fail.
op := &oto.NewContextOptions{}
op.SampleRate = 48000
op.ChannelCount = 2
_, _, err := oto.NewContext(op)
if err == nil {
t.Fatal("NewContext after the context was created must return an error")
}
}