MCPcopy
hub / github.com/g3n/engine / NewAudioFile

Function NewAudioFile

audio/audio_file.go:45–66  ·  view source on GitHub ↗

NewAudioFile creates and returns a pointer to a new audio file object and an error

(filename string)

Source from the content-addressed store, hash-verified

43
44// NewAudioFile creates and returns a pointer to a new audio file object and an error
45func NewAudioFile(filename string) (*AudioFile, error) {
46
47 // Checks if file exists
48 _, err := os.Stat(filename)
49 if err != nil {
50 return nil, err
51 }
52
53 af := new(AudioFile)
54
55 // Try to open as a wave file
56 if af.openWave(filename) == nil {
57 return af, nil
58 }
59
60 // Try to open as an ogg vorbis file
61 if af.openVorbis(filename) == nil {
62 return af, nil
63 }
64
65 return nil, fmt.Errorf("Unsuported file type")
66}
67
68// Close closes the audiofile
69func (af *AudioFile) Close() error {

Callers 1

NewPlayerFunction · 0.85

Calls 2

openWaveMethod · 0.80
openVorbisMethod · 0.80

Tested by

no test coverage detected