Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MP3 support not available #299

Closed
shibingli opened this issue Dec 23, 2017 · 10 comments
Closed

MP3 support not available #299

shibingli opened this issue Dec 23, 2017 · 10 comments
Labels
solved? This issue might have been solved but not tested

Comments

@shibingli
Copy link

shibingli commented Dec 23, 2017

package main

import (
	"log"

	"github.com/veandco/go-sdl2/sdl"
	"github.com/veandco/go-sdl2/mix"
)

func main() {
	if err := sdl.Init(sdl.INIT_AUDIO); err != nil {
		log.Println(err)
		return
	}
	defer sdl.Quit()

	if err := mix.Init(mix.INIT_MP3); err != nil {
		log.Println(err)
		return
	}
	defer mix.Quit()

	if err := mix.OpenAudio(22050, mix.DEFAULT_FORMAT, 2, 4096); err != nil {
		log.Println(err)
		return
	}
	defer mix.CloseAudio()

	if music, err := mix.LoadMUS("../../assets/test.mp3"); err != nil {
		log.Println(err)
	} else if err = music.Play(1); err != nil {
		log.Println(err)
	} else {
		sdl.Delay(5000)
		music.Free()
	}
}

Mac OS 10.13.2

brew install sdl2_mixer --with-flac --with-fluid-synth --with-libmikmod --with-libmodplug --with-smpeg2 --with-mpg123

@veeableful
Copy link
Contributor

Hmm weird, it seems to not work on my Linux laptop too. I'll check on this more when I'm back from overseas.

@shibingli
Copy link
Author

Thanks.

@veeableful
Copy link
Contributor

It seems like sdl2_mixer 2.0.2's MP3 support is broken? When I reverted to 2.0.1 on both Linux and macOS, it seems to work.

on macOS, I had to checkout Homebrew's formula back to when sdl2_mixer was still 2.0.1. Something like this (assuming sdl2 and sdl2_mixer aren't installed yet):

  1. cd $(brew --repo homebrew/core)
  2. git checkout 956d9f
  3. HOMEBREW_NO_AUTO_UPDATE=1 brew install sdl2_mixer --with-smpeg2
  4. git checkout master

If everything performed successfully, you should be able to run the program with MP3 support.

@pgaskin
Copy link

pgaskin commented Jan 12, 2018

Can confirm with OGG on Arch Linux. Downgrading worked.

@veeableful veeableful added the solved? This issue might have been solved but not tested label Jan 12, 2018
@ryancheung
Copy link

@veeableful Thanks! You're really save me from dying of trying to figure out why MP3 not supported in macOS.

@ryancheung
Copy link

For the latest homebrew, run brew install sdl2_mixer --with-mpg123 can fix all these trouble.

@veeableful
Copy link
Contributor

Thanks @ryancheung! I'll add that command to the README as alternate installation method for macOS, maybe eventually replace the current one.

@flipkick
Copy link

flipkick commented Jun 26, 2019

This behavior in sdl2_mixer 2.02 comes from a bug mentioned in: https://discourse.libsdl.org/t/bug-sdl2-mixer-init-error-format-support-not-available/23705/2

Workaround: Call Mix.OpenAudio before Mix.Init, like this:

package main

import (
	"log"

	"github.com/veandco/go-sdl2/sdl"
	"github.com/veandco/go-sdl2/mix"
)

func main() {
	if err := sdl.Init(sdl.INIT_AUDIO); err != nil {
		log.Println(err)
		return
	}
	defer sdl.Quit()

	if err := mix.OpenAudio(22050, mix.DEFAULT_FORMAT, 2, 4096); err != nil {
		log.Println(err)
		return
	}
	defer mix.CloseAudio()

	if err := mix.Init(mix.INIT_MP3); err != nil {
		log.Println(err)
		return
	}
	defer mix.Quit()

	if music, err := mix.LoadMUS("../../assets/test.mp3"); err != nil {
		log.Println(err)
	} else if err = music.Play(1); err != nil {
		log.Println(err)
	} else {
		sdl.Delay(5000)
		music.Free()
	}
}

@jdavid5815
Copy link

jdavid5815 commented Apr 9, 2020

As of February 2019 brew on MacOS doesn't accept options anymore. To get mp3 support working, I had to do the following:

$ brew install mpg123
$ brew edit sdl2_mixer

Look for --disable-music-mp3-mpg123 and change this to --enable-music-mp3-mpg123

$ brew reinstall --build-from-source sdl2_mixer

That fixed it for me.

@mikedesu
Copy link

As of February 2019 brew on MacOS doesn't accept options anymore. To get mp3 support working, I had to do the following:

$ brew install mpg123
$ brew edit sdl2_mixer

Look for --disable-music-mp3-mpg123 and change this to --enable-music-mp3-mpg123

$ brew reinstall --build-from-source sdl2_mixer

That fixed it for me.

Dude yes!!! Thank you so much!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
solved? This issue might have been solved but not tested
Projects
None yet
Development

No branches or pull requests

7 participants