Stop being the product.
Become the owner.
or
sign uplog in

Trying to prevent an overlapping sound in arcade and…

Trying to prevent an overlapping sound in arcade and getting a type error that I'm missing arguments

So, I have the following code. I'm trying to play a sound only if it's not already being played that way it doesn't overlap.

import arcade
ball_sound = arcade.load_sound(r"C:\Projects\spinopel-two-rubber-ball-bouncing-393214.mp3")
window = arcade.Window(1000,1000,title="physics",resizable=True,update_rate=1/60);

class s(arcade.View):
    def __init__(self):
        super().__init__()
        self.sound = ball_sound.play()
    def on_update(self, delta_time):
        if arcade.Sound.is_complete(self.sound):
            self.sound = ball_sound.play()


sim = s()
window.show_view(sim)
arcade.run ()

This raises the following error: TypeError: Sound.is\_complete () missing 1 required positional argument: 'player'

Now, if my reading of the arcade docs is correct, ball\_sound.play() returns a player object. arcade.Sound.is\_complete () requires only 1 argument, and that's a player object. So I'm not sure why the error is happening considering I'm passing in a player object.


What's interesting though, I eventually got annoyed enough that I just said "Fine, If you want an additional argument, you can have one". So I rewrote

`if arcade.Sound.is_complete(self.sound):`

to

`if arcade.Sound.is_complete(self.sound,self.sound):`

For some reason, this fixed the TypeError, which makes no sense to me considering I'm passing in 2 arguments when is\_complete() asks for exactly 1. The program even compiles and runs for a bit! Well, until the sound finishes playing in which case the following error occurs.

Traceback (most recent call last):
File "c:\Projects\test.py", line 16, in <module>
arcade.run ()
File "C:\Users\my_name\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\arcade\window_commands.py", line 152, in run
pyglet.app.run(None )
File "C:\Users\my_name\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\pyglet\app\__init__.py", line 81, in run
event_loop.run(interval)
File "C:\Users\my_name\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\pyglet\app\base.py", line 164, in run
timeout = self.idle()
^^^^^^^^^^^
File "C:\Users\my_name\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\pyglet\app\base.py", line 232, in idle
self.clock.call_scheduled_functions(dt)
File "C:\Users\my_name\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\pyglet\clock.py", line 217, in call_scheduled_functions
item.func(now - item.last_ts, *item.args, **item.kwargs)
File "C:\Users\my_name\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\arcade\application.py", line 545, in _dispatch_frame
self._dispatch_updates(delta_time)
File "C:\Users\my_name\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\arcade\application.py", line 579, in _dispatch_updates
self.dispatch_event("on_update", GLOBAL_CLOCK.delta_time)
File "C:\Users\my_name\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\pyglet\window\__init__.py", line 686, in dispatch_event
super().dispatch_event(*args)
File "C:\Users\my_name\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\pyglet\event.py", line 364, in dispatch_event
if handler(*args):
^^^^^^^^^^^^^^
File "c:\Projects\test.py", line 11, in on_update
if arcade.Sound.is_complete(self.sound,self.sound):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\my_name\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\arcade\sound.py", line 171, in is_complete
return player.time >= self.source.duration # type: ignore
^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'duration'


Does anyone know what I'm misunderstanding?
#technology #dev #programming
source
earnings
2,000 mlx total
$0  total
engagement
3 views
0 reactions

0 comments