


Unable to initialize music using SDL2_Mixer, reporting unrecognized audio format
php Editor Banana encountered a problem when using SDL2_Mixer to initialize music, and the report showed an unrecognized audio format. This problem may affect the music playback function and cause inconvenience to users. In order to solve this problem, we need to find the cause of the unrecognized audio format and take appropriate measures to fix it. The following will introduce some possible causes and solutions, hoping to help developers who encounter similar problems.
Question content
My application utilizes sdl2 to render weather data to a window, and I want to play some music in the background indefinitely from the resulting queue. I've done that part, but loading the music is where the problem occurs. Every time I try to load a song in the queue it says unrecognized audio format. This is what my code looks like.
Lines 277 - 280, when I initialize the sdl for audio and video. Works fine.
if err := sdl.init(sdl.init_audio | sdl.init_video); err != nil { log.fatalf("failed to initialize sdl: %s", err) } defer sdl.quit()
Lines 282 to 285, when I initialize the mixer. The effect is also very good.
if err := mix.init(mix.init_flac | mix.init_ogg); err != nil { log.fatalf("failed to initialize mixer: %s", err) } defer mix.quit()
Lines 292 - 305 when I populate the music queue. Also works fine.
var music []string err = filepath.walk("assets/music", func(path string, info os.fileinfo, err error) error { if err != nil { return err } if !info.isdir() && (filepath.ext(path) == ".flac" || filepath.ext(path) == ".ogg") { music = append(music, path) } return nil }) if err != nil { log.fatalf("failed to queue music: %s", err) return }
Shortly after, lines 307 - 314, when I try to loadmus every file in the queue. This is where the problem arises.
for _, file := range music { music, err := mix.loadmus(file) if err != nil { log.fatalf("failed to load music: %s", err) continue } defer music.free() }
When I have the above code in my program, go will print this code.
2023/03/30 19:57:18 failed to load music: unrecognized audio format
I'm trying to load a flac file converted from ffmpeg. I also tried using mp3 files and wav files (by changing the initialization flags and files in the assets to their working counterparts) but they didn't work well.
If it helps, the operating system I'm using is windows 11, and I'm using msys2 to enable go's sdl module to utilize the sdl2 library. I also use the following command to compile my code.
go build -ldflags="-s -w" -gcflags="-trimpath=$PWD" -race main.go
Solution
You need to open the audio device before loading sounds. Call mix.openaudio
or mix.openaudiodevice
with appropriate parameters, e.g.
mix.OpenAudio(48000, sdl.AUDIO_S16, 2, 4096);
The above is the detailed content of Unable to initialize music using SDL2_Mixer, reporting unrecognized audio format. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

OpenSSL, as an open source library widely used in secure communications, provides encryption algorithms, keys and certificate management functions. However, there are some known security vulnerabilities in its historical version, some of which are extremely harmful. This article will focus on common vulnerabilities and response measures for OpenSSL in Debian systems. DebianOpenSSL known vulnerabilities: OpenSSL has experienced several serious vulnerabilities, such as: Heart Bleeding Vulnerability (CVE-2014-0160): This vulnerability affects OpenSSL 1.0.1 to 1.0.1f and 1.0.2 to 1.0.2 beta versions. An attacker can use this vulnerability to unauthorized read sensitive information on the server, including encryption keys, etc.

Backend learning path: The exploration journey from front-end to back-end As a back-end beginner who transforms from front-end development, you already have the foundation of nodejs,...

Queue threading problem in Go crawler Colly explores the problem of using the Colly crawler library in Go language, developers often encounter problems with threads and request queues. �...

The library used for floating-point number operation in Go language introduces how to ensure the accuracy is...

Under the BeegoORM framework, how to specify the database associated with the model? Many Beego projects require multiple databases to be operated simultaneously. When using Beego...

The difference between string printing in Go language: The difference in the effect of using Println and string() functions is in Go...

The problem of using RedisStream to implement message queues in Go language is using Go language and Redis...

What should I do if the custom structure labels in GoLand are not displayed? When using GoLand for Go language development, many developers will encounter custom structure tags...
