-
Notifications
You must be signed in to change notification settings - Fork 13
Description
Thanking you for your project, I would like to ask if you can give me an example using the seek method, to forward or reverse playback. The request is motivated by the fact that the examples you provided need to be updated, because timeunits is in flagh and not in enums as you indicated.
This is the class I'm building, but I can't do the seek method, because doesn't work
import pyfmodex
from pyfmodex.enums import DSP_MULTIBAND_EQ, DSP_MULTIBAND_EQ_FILTER_TYPE, DSP_TYPE
from pyfmodex.flags import TIMEUNIT
class SoundPlayer:
def init(self, sound_file):
# Initialize FMOD System
self.system = pyfmodex.System()
self.system.init(maxchannels=1)
# Create the master channel group
self.mastergroup = self.system.master_channel_group
# Load sound file
self.sound = self.system.create_sound(sound_file)
self.channel = None
#...
def seek(self, time_ms):
# Imposta la posizione di riproduzione del suono in base al tempo fornito in millisecondi
if self.channel and self.sound:
sound_length_ms = self.sound.get_length(TIMEUNIT.MS)
if sound_length_ms > 0:
sound_length_samples = self.sound.get_length(TIMEUNIT.PCM)
time_ms = max(0, min(time_ms, sound_length_ms))
position_samples = int(time_ms / 1000 * self.sound.default_frequency)
position_samples = max(0, min(position_samples, sound_length_samples))
self.channel.set_position(position_samples, TIMEUNIT.PCM)
self.system.update() # Update the FMOD system to apply the new position