Skip to content

Commit

Permalink
Merge pull request #4 from wsc1/master
Browse files Browse the repository at this point in the history
flac registration
  • Loading branch information
wsc1 committed Sep 10, 2018
2 parents defcac8 + 5e6e7b0 commit c422617
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 5 deletions.
2 changes: 1 addition & 1 deletion doc.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018 The ZikiChomgo Authors. All rights reserved. Use of this source
// Copyright 2018 The ZikiChombo Authors. All rights reserved. Use of this source
// code is governed by a license that can be found in the License file.

// Package ext houses zc collaboration with external imports.
Expand Down
2 changes: 1 addition & 1 deletion flac/decoder.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018 The ZikiChomgo Authors. All rights reserved. Use of this source
// Copyright 2018 The ZikiChombo Authors. All rights reserved. Use of this source
// code is governed by a license that can be found in the License file.

// TODO: add seek support; only enabled in the dev branch of mewkiz/flac.
Expand Down
28 changes: 26 additions & 2 deletions flac/decoder_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
// Copyright 2018 The ZikiChomgo Authors. All rights reserved. Use of this source
// Copyright 2018 The ZikiChombo Authors. All rights reserved. Use of this source
// code is governed by a license that can be found in the License file.

package flac

import "zikichombo.org/sound"
import (
"os"
"testing"

"zikichombo.org/codec"
"zikichombo.org/sio"
"zikichombo.org/sound"
)

// Assert that flac.Decoder implements the sound.Source interface.
var _ sound.Source = (*Decoder)(nil)

func TestRegister(t *testing.T) {
co, err := codec.CodecFor(".flac", nil)
if err != nil {
t.Fatal(err)
}
f, err := os.Open("0.flac")
if err != nil {
t.Fatal(err)
}
dec, _, err := co.Decoder(f)
if err != nil {
t.Fatal(err)
}
defer dec.Close()
sio.Play(dec)
}
2 changes: 1 addition & 1 deletion flac/doc.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018 The ZikiChomgo Authors. All rights reserved. Use of this source
// Copyright 2018 The ZikiChombo Authors. All rights reserved. Use of this source
// code is governed by a license that can be found in the License file.

// Package flac provides decoding of FLAC audio streams.
Expand Down
29 changes: 29 additions & 0 deletions flac/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2018 The ZikiChombo Authors. All rights reserved. Use of this source
// code is governed by a license that can be found in the License file.

package flac

import (
"io"

"zikichombo.org/codec"
"zikichombo.org/sound"
"zikichombo.org/sound/sample"
)

type flacCodec struct {
codec.NullCodec
}

func (f *flacCodec) Extensions() []string {
return []string{".flc", ".flac"}
}

func (f *flacCodec) Decoder(rc io.ReadCloser) (sound.Source, sample.Codec, error) {
dec, err := NewDecoder(rc)
return dec, codec.AnySampleCodec, err
}

func init() {
codec.RegisterCodec(&flacCodec{})
}

0 comments on commit c422617

Please sign in to comment.