So like the title asks, using Python, would I be able to use a property to go to a specific time in a sound file? If it is possible, would it work in seconds/minutes or frames? As far as I know, there isn’t much that can be done with sound in Blender so I’m not sure if this can be done.
import bge
import aud
from bge.logic import expandPath
# Basic references
cont = bge.logic.getCurrentController()
own = cont.owner
device = aud.device()
# Sensors
forward = cont.sensors['forward'] # Right key
rewind = cont.sensors['rewind'] # Left key
toggle_pause = cont.sensors['toggle_pause'] # Spacebar key
# Initialize sound
if not 'handle' in own:
# Loads the factory into memory
factory = aud.Factory(expandPath('//Lalalalalala.mp3'))
# Plays the factory and stores its handle reference for later
# keep=True keeps the handle in memory even if sound ended playing
own['handle'] = device.play(factory, keep=True)
# A negative loop_count makes the handle repeat infinitely
own['handle'].loop_count = -1
# Value to keep track of handle status
own['handle_status'] = 'playing'
# When spacebar is pressed
if toggle_pause.positive:
# Pause handle if status is playing
if own['handle_status'] == 'playing':
own['handle'].pause()
own['handle_status'] = 'paused'
# Resume handle if status is paused
else:
own['handle'].resume()
own['handle_status'] = 'playing'
# Fast forward by 2 seconds
if forward.positive:
own['handle'].position += 2
# Rewind by 2 seconds
if rewind.positive:
own['handle'].position -= 2