Register Decoder With Default Output Ext

This commit is contained in:
Emmm Monster
2020-12-26 16:07:48 +08:00
parent d5031e1935
commit 91e23a20dd
5 changed files with 59 additions and 31 deletions

View File

@ -1,9 +1,11 @@
package common
type RawDecoder struct {
file []byte
file []byte
audioExt string
}
//goland:noinspection GoUnusedExportedFunction
func NewRawDecoder(file []byte) Decoder {
return &RawDecoder{file: file}
}
@ -25,17 +27,21 @@ func (d RawDecoder) GetAudioData() []byte {
}
func (d RawDecoder) GetAudioExt() string {
return ""
return d.audioExt
}
func (d RawDecoder) GetMeta() Meta {
return nil
}
func init() {
RegisterDecoder("mp3", NewRawDecoder)
RegisterDecoder("flac", NewRawDecoder)
RegisterDecoder("wav", NewRawDecoder)
RegisterDecoder("ogg", NewRawDecoder)
RegisterDecoder("m4a", NewRawDecoder)
func DecoderFuncWithExt(ext string) NewDecoderFunc {
return func(file []byte) Decoder {
return &RawDecoder{file: file, audioExt: ext}
}
}
func init() {
RegisterDecoder("mp3", DecoderFuncWithExt("mp3"))
RegisterDecoder("flac", DecoderFuncWithExt("flac"))
RegisterDecoder("wav", DecoderFuncWithExt("wav"))
RegisterDecoder("ogg", DecoderFuncWithExt("ogg"))
RegisterDecoder("m4a", DecoderFuncWithExt("m4a"))
}