-
Notifications
You must be signed in to change notification settings - Fork 4
API Usage
- Include the iaudio.h in public folder.
- Query the interface in AllPluginsLoaded and use it like this:
// in AllPluginsLoaded
IAudio *pAudio = (IAudio*)g_SMAPI->MetaFactory(AUDIO_INTERFACE, nullptr, nullptr);
// wherever you like
std::string str = "D:/xxx.mp3";
pAudio->PlayFromFile(str, 1.0f);- Copy the Audio.cs in public folder to your project.
- Use the method in
Audioclass.
- Download
swext_audio_windowsorswext_audio_linuxin releases. - Decompress it and put the
.dllor.sofile inswiftly/extensions/(platform)/folder. - Initialize it like this:
local audio = Audio()
audio:PlayFromFile("D:/xxx.mp3", 1.0)Enable / disable the audio to a specific player, the audio still plays even if they can't hear it.
| Params | Type | Description |
|---|---|---|
| slot | int |
player slot |
| hearing | boolean |
hearing or not |
Metamod Usage
pAudio->SetPlayerHearing(slot, hearing);CounterStrikeSharp Usage
Audio.SetPlayerHearing(slot, hearing);Swiftly Usage
audio:SetPlayerHearing(slot, hearing)Enable / disable the audio to all players, the audio still plays even if they can't hear it.
| Params | Type | Description |
|---|---|---|
| hearing | boolean |
hearing or not |
Metamod Usage
pAudio->SetAllHearing(hearing);CounterStrikeSharp Usage
Audio.SetAllHearing(hearing);Swiftly Usage
audio:SetAllHearing(hearing)Return if a player is hearing or not.
| Params | Type | Description |
|---|---|---|
| slot | int |
player slot |
| Return | Type | Description |
|---|---|---|
| hearing | boolean |
hearing or not |
Metamod Usage
auto hearing = pAudio->IsHearing(slot);CounterStrikeSharp Usage
var hearing = Audio.IsHearing(slot);Swiftly Usage
local hearing = audio:IsHearing(slot)Play an audio buffer to specific player. The audio buffer can be in any format as long as it can be recognized by ffmpeg.
| Params | Type | Description |
|---|---|---|
| slot | int |
player slot |
| audioBuffer |
std::string or string
|
audio buffer |
| volume | float |
default 1.0 |
Metamod Usage
pAudio->PlayToPlayerFromBuffer(slot, audioBuffer, volume);CounterStrikeSharp Usage
Audio.PlayToPlayerFromBuffer(slot, audioBuffer, volume);Swiftly Usage
audio:PlayToPlayerFromBuffer(slot, audioBuffer, volume)Play an audio file to specific player. The audio path is recommended to be absolute path.
| Params | Type | Description |
|---|---|---|
| slot | int |
player slot |
| audioPath |
std::string or string
|
audio path, absolute path is recommended |
| volume | float |
default 1.0 |
Metamod Usage
pAudio->PlayToPlayerFromFile(slot, audioPath, volume);CounterStrikeSharp Usage
Audio.PlayToPlayerFromFile(slot, audioPath, volume);Swiftly Usage
audio:PlayToPlayerFromFile(slot, audioPath, volume)Play an audio buffer to ALL players. The audio buffer can be in any format as long as it can be recognized by ffmpeg.
| Params | Type | Description |
|---|---|---|
| audioBuffer |
std::string or string
|
audio buffer |
| volume | float |
default 1.0 |
Metamod Usage
pAudio->PlayFromBuffer(audioBuffer, volume);CounterStrikeSharp Usage
Audio.PlayFromBuffer(audioBuffer, volume);Swiftly Usage
audio:PlayFromBuffer(audioBuffer, volume)Play an audio file to ALL players. The audio path is recommended to be absolute path.
| Params | Type | Description |
|---|---|---|
| audioPath |
std::string or string
|
audio path, absolute path is recommended |
| volume | float |
default 1.0 |
Metamod Usage
pAudio->PlayFromFile(audioPath, volume);CounterStrikeSharp Usage
Audio.PlayFromFile(audioPath, volume);Swiftly Usage
audio:PlayFromFile(audioPath, volume)Return if theres an audio playing to specific player now.
| Params | Type | Description |
|---|---|---|
| slot | int |
player slot |
| Return | Type | Description |
|---|---|---|
| playing | boolean |
playing or not |
Metamod Usage
bool playing = pAudio->IsPlaying(slot);CounterStrikeSharp Usage
bool playing = Audio.IsPlaying(slot);Swiftly Usage
local playing = audio:IsPlaying(slot)Return if theres an audio playing to ALL players now.
| Return | Type | Description |
|---|---|---|
| playing | boolean |
playing or not |
Metamod Usage
bool playing = pAudio->IsAllPlaying();CounterStrikeSharp Usage
bool playing = Audio.IsAllPlaying();Swiftly Usage
local playing = audio:IsAllPlaying()Register a listener when a play starts.
| Params | Type | Description |
|---|---|---|
| handler | Function (int slot) => void |
the handler, slot is player slot, -1 if global |
| Return | Type | Description |
|---|---|---|
| id | int |
The id of the registered handler. Use this to unregister it. |
Metamod Usage
void Handler(int slot)
{
// xxx
}
pAudio->RegisterPlayStartListener(&Handler);CounterStrikeSharp Usage
public static void PlayStartHandler(int slot)
{
// xxx
}
Audio.RegisterPlayStartListener(PlayStartHandler);Swiftly Usage
local handler = function (slot)
// xxx
end
audio:RegisterPlayStartListener(handler)Unregister a listener when a play starts.
| Params | Type | Description |
|---|---|---|
handler or handler id
|
int or Function
|
the handler, metamod use handler id, css and swiftly use handler |
Metamod Usage
int id = pAudio->RegisterPlayStartListener(&Handler);
pAudio->UnregisterPlayStartListener(id);CounterStrikeSharp Usage
Audio.UnregisterPlayStartListener(PlayStartHandler);Swiftly Usage
audio:UnregisterPlayStartListener(handler)Register a listener when a play ends.
| Params | Type | Description |
|---|---|---|
| handler | Function (int slot) => void |
the handler, slot is player slot, -1 if global |
| Return | Type | Description |
|---|---|---|
| id | int |
The id of the registered handler. Use this to unregister it. |
Metamod Usage
void Handler(int slot)
{
// xxx
}
pAudio->RegisterPlayEndListener(&Handler);CounterStrikeSharp Usage
public static void PlayEndHandler(int slot)
{
// xxx
}
Audio.RegisterPlayEndListener(PlayEndHandler);Swiftly Usage
local handler = function (slot)
// xxx
end
audio:RegisterPlayEndListener(handler)Unregister a listener when a play ends.
| Params | Type | Description |
|---|---|---|
handler or handler id
|
int or Function
|
the handler, metamod use handler id, css and swiftly use handler |
Metamod Usage
int id = pAudio->RegisterPlayEndListener(&Handler);
pAudio->UnregisterPlayEndListener(id);CounterStrikeSharp Usage
Audio.UnregisterPlayEndListener(PlayEndHandler);Swiftly Usage
audio:UnregisterPlayEndListener(handler)Register a listener when a play net message being sent, basically will be called per 40 milliseconds.
| Params | Type | Description |
|---|---|---|
| handler | Function (int slot, int progress) => void |
the handler, slot is player slot, -1 if global, progress is in milliseconds |
| Return | Type | Description |
|---|---|---|
| id | int |
The id of the registered handler. Use this to unregister it. |
Metamod Usage
void Handler(int slot, int progress)
{
// xxx
}
pAudio->RegisterPlayListener(&Handler);CounterStrikeSharp Usage
public static void PlayHandler(int slot, int progress)
{
// xxx
}
Audio.RegisterPlayListener(PlayHandler);Swiftly Usage
local handler = function (slot, progress)
// xxx
end
audio:RegisterPlayListener(handler)Unregister the play listener.
| Params | Type | Description |
|---|---|---|
handler or handler id
|
int or Function
|
the handler, metamod use handler id, css and swiftly use handler |
Metamod Usage
int id = pAudio->RegisterPlayListener(&Handler);
pAudio->UnregisterPlayListener(id);CounterStrikeSharp Usage
Audio.UnregisterPlayListener(PlayHandler);Swiftly Usage
audio:UnregisterPlayListener(handler)Set the player of the audio.
| Params | Type | Description |
|---|---|---|
slot |
int |
default -1, can be invalid, when it's valid, the game will show the player with that slot as the player of the audio, when it's invalid, the game won't show the player |
Metamod Usage
pAudio->SetPlayer(slot);CounterStrikeSharp Usage
Audio.SetPlayer(slot);Swiftly Usage
audio:SetPlayer(slot)