Beispiel #1
0
// Create a new music and load it from a file
// This function doesn't start playing the music (call
// Play() to do so).
// Here is a complete list of all the supported audio formats:
// ogg, wav, flac, aiff, au, raw, paf, svx, nist, voc, ircam,
// w64, mat4, mat5 pvf, htk, sds, avr, sd2, caf, wve, mpc2k, rf64.
// \param filename Path of the music file to open
// \return A new sfMusic object (NULL if failed)
func NewMusicFromFile(filename string) (Music, error) {
	fn := C.CString(filename)
	m := Music{C.sfMusic_createFromFile(fn)}
	if fn == nil {
		return m, errors.New("NewMusicFromFile fails to open: " + filename)
	}
	return m, nil
	// sfMusic* sfMusic_createFromFile(const char* filename);
}
Beispiel #2
0
// NewMusic creates a new music object from the reader
// Note: this will close the Reader if closable
func NewMusic(r io.Reader) Music {
	if c, ok := r.(io.Closer); ok {
		defer c.Close()
	}
	m := Music{}
	f, ok := r.(*os.File)
	if !ok {
		var err error
		f, err = ioutil.TempFile("", "stream_")
		if err != nil {
			panic(err)
		}
		defer f.Close()
		_, err = io.Copy(f, r)
		if err != nil {
			panic(err)
		}
		m.f = f.Name()
	}
	str := C.CString(f.Name())
	defer C.free(unsafe.Pointer(str))
	m.internal = C.sfMusic_createFromFile(str)
	return m
}