# Chapter 14: The Audio System

The `AudioPlayer` struct forms the core of the audio system for this game. This system uses the `sdl2::mixer` module from the `SDL2` library in Rust. It can load and play `.mp3`, `.flac`, `.mod`, and `.ogg` audio files. The `AudioPlayer` struct contains a single field - `mixer_context`.

An `AudioPlayer` is instantiated with a specific number of channels (`numchans`). The constructor function (`new`) initializes SDL2, opens an audio device with a specific frequency, chunk size, and number of channels.

It provides a method `play` that loads an audio file, plays it in a loop a given number of times and sets its volume. The `play` method returns a `Channel` that can be paused, resumed, or stopped using the respective methods in `AudioPlayer`.

When an `AudioPlayer` instance is dropped, it ends the currently playing music and prints a message to the console.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lados-organization.gitbook.io/goku/chapter-14-the-audio-system.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
