Sounds in BGE, play packed sound file

Game Engine, Players & Web Plug-in, Virtual Reality, support for other engines

Moderators: jesterKing, stiv

przemekk
Posts: 9
Joined: Tue Jan 25, 2011 9:08 am

Sounds in BGE, play packed sound file

Postby przemekk » Wed Apr 04, 2012 2:24 pm

There is a possibility to use aud module to play the sound file. It is easy to load the file from disk. But how to load the file from the resource packed into the blend file?

In Blender i can do something like that

Code: Select all

    import aud
    import bpy
    device = aud.device()

    factory = bpy.data.sounds['39068__alienbomb_.000'].factory
    GameLogic.snd_4 = aud.Factory.buffer(factory)


But in Game Engine the module bpy is not available.

So the question is how to create the factory for file stored as packed resource in Game Engine. Any suggestions?[/code]

przemekk
Posts: 9
Joined: Tue Jan 25, 2011 9:08 am

Using packed resources to play sound

Postby przemekk » Wed Apr 04, 2012 11:23 pm

The easiest sollution (thanks to Dalai) is to create actuators with sounds and to get the factory from the actuators, like this:

Code: Select all

co = GameLogic.getCurrentController()
act = co.actuators['sound_1']

import aud
device = aud.device()
factory = act.sound
snd_handle = device.play(factory)



Return to “Interactive 3d”

Who is online

Users browsing this forum: No registered users and 1 guest