Raised This Month: $51 Target: $400
 12% 

PrecacheSound not working?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ReyZ
Junior Member
Join Date: Oct 2020
Old 06-25-2021 , 04:29   PrecacheSound not working?
Reply With Quote #1

PHP Code:
public void OnMapStart() {
    
PrecacheSound("sound/test/test.mp3"true);
    
AddFileToDownloadsTable("sound/test/test.mp3");

When i use
PHP Code:
EmitSoundToClient(client"sound/test/test.mp3"); 
Gives client error
Code:
MP3 initialized with no sound cache, this may cause janking. [ sound\test\test.mp3 ]
Failed to create decoder for MP3 [ sound\test\test.mp3 ]
*** Invalid sample rate (0) for sound 'sound\test\test.mp3'.
ReyZ is offline
MAGNAT2645
Senior Member
Join Date: Nov 2015
Location: AlliedMods.net
Old 06-25-2021 , 08:08   Re: PrecacheSound not working?
Reply With Quote #2

Path to sound (1st argument) in PrecacheSound is already relative to "sound" directory so you should remove "sound/" part.
Code:
PrecacheSound("test/test.mp3", true);
Same for EmitSound* functions.
Code:
EmitSoundToClient(client, "test/test.mp3");
You can even create a macro for convenience.
Code:
#define MY_SOUND "test/test.mp3" // you can just change path here and don't have to change in other places

public void OnMapStart() {
    PrecacheSound(MY_SOUND, true);
    AddFileToDownloadsTable("sound/" ... MY_SOUND); // string concatenation (only during compilation)
}

// Somewhere in code
EmitSoundToClient(client, MY_SOUND);
__________________

Last edited by MAGNAT2645; 06-25-2021 at 08:14.
MAGNAT2645 is offline
ReyZ
Junior Member
Join Date: Oct 2020
Old 06-25-2021 , 10:24   Re: PrecacheSound not working?
Reply With Quote #3

Quote:
Originally Posted by MAGNAT2645 View Post
Path to sound (1st argument) in PrecacheSound is already relative to "sound" directory so you should remove "sound/" part.
Code:
PrecacheSound("test/test.mp3", true);
Same for EmitSound* functions.
Code:
EmitSoundToClient(client, "test/test.mp3");
You can even create a macro for convenience.
Code:
#define MY_SOUND "test/test.mp3" // you can just change path here and don't have to change in other places

public void OnMapStart() {
    PrecacheSound(MY_SOUND, true);
    AddFileToDownloadsTable("sound/" ... MY_SOUND); // string concatenation (only during compilation)
}

// Somewhere in code
EmitSoundToClient(client, MY_SOUND);
Thanks a lot

Last edited by ReyZ; 06-25-2021 at 10:25.
ReyZ is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 19:13.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode