Rust-SDL2 / rust-sdl2

SDL2 bindings for Rust
MIT License
2.78k stars 474 forks source link

Unable to link properly to SDL2_mixer on aarch64 Android #1384

Open ionarevamp opened 7 months ago

ionarevamp commented 7 months ago

The dependency is defined as such in Cargo.toml:

[target.'cfg(all(target_os = "android"))'.dependencies.sdl2]
git = "https://github.com/rust-sdl2/rust-sdl2"
default-features = false
features = ["ttf","image","gfx","mixer"]

However, I get this error when calling sdl2::mixer::init(...)

= note: ld.lld: error: undefined symbol: Mix_Init
          >>> referenced by ....rcgu.o:([project]::main::hf704b2d9cfbfac9d)

          ld.lld: error: undefined symbol: Mix_Quit
          >>> referenced by ....rcgu.o:([project]::main::hf704b2d9cfbfac9d)
          cc: error: linker command failed with exit code 1 (use -v to see invocation)

Linking statically without the NDK doesn't work (and I don't want to use it as it doesn't seem to work correctly anyways and takes up too much space on this device), and specifying -L or -l flags doesn't fix the problem either.

I would really like to use the mixer library for volume control when playing music, as the next best thing for high-quality gapless playback is to use the queuing methods which don't have direct volume control. If anyone knows a good workaround in the meantime that would be great.

ionarevamp commented 7 months ago

By the way, I had the idea to do my own form of audio queueing by effectively concatenating the data buffers of different loaded files, one after another. I'll do that when I have some free time and make another comment about its effectiveness. In theory, it should work though.

ionarevamp commented 7 months ago

Using a Sound struct and implementing the callback function for it (based on the wav file example), I was able to then call the .lock() method on a generated AudioDevice<Sound> instance and append the contained data vector with that of another wav file. It works perfectly. Now just to make some changes to the Vec structure and the callback function, along with writing a couple new audio-pairing functions, and I should be able to mix audio ""manually"" without the need to link to the mixer library.