Wrong args/parameters for emit_sound

Please post any questions about developing your plugin here. Please use the search function before posting!
arawra
Senior Member
Posts: 190
Joined: Fri Jun 21, 2013 6:51 am

Wrong args/parameters for emit_sound

Postby arawra » Tue Feb 16, 2021 7:08 pm

Not sure if this is something I am doing wrong, or if the wrong parameter type is being passed as part of SourcePython.

Syntax: Select all

def playVideo(videoLink):
if not os.path.exists(songDir):
try:
os.mkdir(songDir)
except:
message("Couldn't create song dir!")
return
if len(os.listdir()) > 0:
for x in os.listdir():
os.remove(x)
else:
message('No songs to delete')

url = videoLink
video = pafy.new(url)
best = video.getbestaudio()
best.download()
song = os.listdir(songDir)[0]
message(song)
message(format("Playing {0} {1}".format(video.title, video.duration)))

for p in PlayerIter():
p.play_sound(song, video.duration)


Code: Select all

Boost.Python.ArgumentError: Python argument types in
    _EngineSound.emit_sound(_EngineSound, RecipientFilter, int, Channel, str, str, Attenuation, SoundFlags, Pitch, Vector, Vector, tuple, bool, float, int)
did not match C++ signature:
    emit_sound(class IEngineSound *, class MRecipientFilter {lvalue}, int, int, char const *, float, float, int flags=0, int pitch=100, class Vector const * origin=None, class Vector const * direction=None, class boost::python::tuple origins=(), bool update_positions=True, float sound_time=0.0, int speaker_entity=-1)


Parameter 6 (which is pitch) passes a string type to a float type. This parameter is responsible for the pitch.

https://github.com/ValveSoftware/source ... em.cpp#L89
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: Wrong args/parameters for emit_sound

Postby satoon101 » Tue Feb 16, 2021 7:53 pm

The second argument, if you aren't giving keywords for them, in Player.play_sound is volume, not duration:
https://github.com/Source-Python-Dev-Te ... #L715-L721

My guess is that video.duration is a string value, and the internal call to emit_sound is expecting a float for the volume argument. If you want to set the duration, you should try to include the keyword sound_time in that call:

Syntax: Select all

p.play_sound(song, sound_time=video.duration)


* Edit: and, if I am right and video.duration is a string for some reason, you might need to cast that to a float or integer.
Image

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 12 guests