WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Sound doesn't play from director functions (https://forum.worldviz.com/showthread.php?t=1577)

roman_suvorov 07-26-2008 02:36 PM

Sound doesn't play from director functions
 
Hello, when running a sample script like this one:

Code:

import viz
viz.go()

def playSound():
        sound = viz.addAudio("quack.wav")
        sound.play()
        return
       
viz.director(playSound)

.. no sound is played and the following error message is displayed:

Code:


** ERROR: Failed to create graph builder (CoInitialize has not been called. )
** ERROR: Failed to load audio 'quack.wav'

However, this works fine:
Code:

import viz
viz.go()
sound = viz.addAudio("quack.wav")
sound.play()

.. so I figured this must have something to do with Vizard's handling of director functions. Any ideas?

farshizzo 07-29-2008 09:59 AM

You need to add the sound object in the main thread. Once it is added you should be able to play it in other director threads.

If it is necessary for you to add the sound object in the director thread, then you can install the pywin32 library for python and use the following code:
Code:

import viz
import pythoncom
viz.go()

def playSound():

        pythoncom.CoInitialize() #Initialize COM

        sound = viz.addAudio("quack.wav")
        sound.play()

        pythoncom.CoUninitialize() #Uninitialize COM

        return
       
viz.director(playSound)


Gladsomebeast 07-29-2008 12:25 PM

If it takes a while to add the sound, would there be a frame rate blip on the add?

What if you added a 3D model with this method?

farshizzo 07-29-2008 02:28 PM

If the audio takes a while to load, then adding the file during runtime will cause a stall in the framerate. In this case, you would use the modified version of the director function I posted above. This is not the case for 3D models though, they can be added as usual in director functions. The call to pythoncom.CoInitialize() is only necessary for COM/DirectX related objects.

roman_suvorov 07-31-2008 08:31 AM

Thanks farshizzo, very helpful as usual. Works flawlessly now. :)


All times are GMT -7. The time now is 02:20 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC