Moved all bindings to the "bindings" sub-directory
Renamed the CSFML directory to c Renamed the DSFML directory to d --> bindings must now be updated to match the new organization! git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1630 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
parent
0cc5563cac
commit
0e2297af28
417 changed files with 0 additions and 0 deletions
49
bindings/python/samples/sound_stream_py3.py
Executable file
49
bindings/python/samples/sound_stream_py3.py
Executable file
|
@ -0,0 +1,49 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
from PySFML import sf
|
||||
|
||||
class MyCustomStream(sf.SoundStream):
|
||||
|
||||
def Open(self, Filename):
|
||||
# Load the sound data into a sound buffer
|
||||
self.SoundData = sf.SoundBuffer()
|
||||
if not self.SoundData.LoadFromFile(Filename):
|
||||
return False
|
||||
# Initialize the stream with the sound parameters
|
||||
self.Initialize(self.SoundData.GetChannelsCount(), self.SoundData.GetSampleRate())
|
||||
# Copy the audio samples into our internal array
|
||||
self.myBuffer = self.SoundData.GetSamples()
|
||||
return True
|
||||
|
||||
def OnStart(self):
|
||||
self.myOffset = 0
|
||||
self.myBufferSize = 80000
|
||||
return True
|
||||
|
||||
def OnGetData(self):
|
||||
# Check if there is enough data to stream
|
||||
if self.myOffset > len(self.myBuffer):
|
||||
# Returning something else than a string means that we want to stop playing the stream
|
||||
return ""
|
||||
# Data contains the string of samples we will return
|
||||
if self.myOffset + self.myBufferSize >= len(self.myBuffer):
|
||||
print("End of audio data reached")
|
||||
Data = self.myBuffer[self.myOffset:]
|
||||
else:
|
||||
Data = self.myBuffer[self.myOffset:self.myOffset+self.myBufferSize]
|
||||
# Update the offset
|
||||
self.myOffset = self.myBufferSize + self.myOffset
|
||||
return Data
|
||||
|
||||
def Main():
|
||||
Stream = MyCustomStream()
|
||||
Stream.Open("./data/fart.wav")
|
||||
Stream.Play()
|
||||
print("Playing 5 seconds of audio data...")
|
||||
sf.Sleep(5)
|
||||
Stream.Stop()
|
||||
print("Press enter to exit...")
|
||||
input()
|
||||
|
||||
Main()
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue