NewAudioFile creates and returns a pointer to a new audio file object and an error
(filename string)
| 43 | |
| 44 | // NewAudioFile creates and returns a pointer to a new audio file object and an error |
| 45 | func 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 |
| 69 | func (af *AudioFile) Close() error { |
no test coverage detected