How to stop audio with pyglet when file is played? - audio

I'm using this program to play na audio file:
music = pyglet.resource.media('file.wav')
music.play()
pyglet.app.run()
I have a problem: I can't do anything after this program. How to stop the audio file when is played? It's look like a loop.

I think you'd have to include add an eventlistener for the on_eos event.
For an example have a look as this thread on the pyglet Google group.

Related

Winsound.Playsound playing a default sound in Python

winsound.PlaySound('a.wav',winsound.SND_ASYNC) is not able to play the sound that I really want in the game. a.wav is in the same directory as where my python file is located but still, it doesn't work. What should I do? It keeps on playing the windows default sound.

Multithreaded Music Playing with Pygame in Terminal

I am attempting to make a text game and add some music to it and maybe sounds too, however, the "Big and Greatest" answer was Pygame. After testing with it, I found that when you use ANY Pygame function, it stops the current terminal session from printing any more output, this stops the game from continuing.
I first tried the usual...
from pygame import *
def some_function():
mixer.load("music.mp3")
mixer.music.play(0)
clock = time.Clock()
clock.tick(10)
while mixer.music.get_busy():
clock.tick(10)
Rest_of_function
And of course this does not work because it is a loop and is doing it in order so I next tried...
from file_with_music import * #added threading to this file
def main():
file_with_music.start()
Rest_of_Function
This however did not work as the annoying "Welcome to pygame" popup blocked terminal output again...
SO the next step was to make a new file and...
from Main import *
from Intro_Sounds import *
if __name__ == '__main__':
Intro_Thread.start() #Intro did not start because pygame popup was somehow called
Music_Thread.start()
Even after putting them both in threads, it still did not work...
As a side note, there is a function built into Main that is meant to execute
Music_Thread.join()
Music_Thread.stop()
After certain input is met.
The expected result is for it to play music in the background while the terminal continues printing out input and accepting input up until the input that would kill the Music thread is input. Of course, it did not work, and I am at a loss...
How can music be played without freezing the terminal.
The pygame.mixer sadly doesn't have this capability (as far as I know). Use winsound instead:
import winsound # only on windows tho...
winsound.PlaySound('sound.wav', winsound.SND_ASYNC) # this will play the sound and...
print('I can still print :D') # this can still print :D
After trying a few things I found...
Pygame is not friendly with sound and terminal output, so it won't work.
WxPython no longer has a functional sound module, making it useless.
Other projects are abandoned or OS specific...
However, I found that PyOpenAL actually works, although it can't understand mp3 files or 32bit float wav. Instead of using multithreading I switched to multiprocessing (making a 2000 line script to properly learn how the module works) and now the sound plays (and loops) while allowing terminal output.
TL:DR
PyOpenAL is the winner.
please try as follow--
from pygame import *
def some_function():
pygame.mixer.music.load("music.mp3")
pygame.mixer.music.play(0)
clock = time.Clock()
clock.tick(10)
while pygame.mixer.music.get_busy():
clock.tick(10)
Rest_of_function

Why is my sound not playing on desktop but on mobile is playing?

I have mp3 file and I want to play it on my stack.
When I opencard I want to play sound on background.Here code:
on preopencard
play "/Users/PeshZ/Desktop/sound.mp3"
end preopencard
My sound not played.But on ipad it playing.
What's wrong?
To use "play audioclip" the sound file must be uncompressed wav, aif, or au. The LC engine cannot decompress sound files. The audioclip command is very old and has limited use, and it has been deprecated in favor of the player object.
You can play mp3 files on the desktop by setting the filename of a player object to the file path of the sound on disk. Players are much more flexible than the audioclip method.
iOS supports mp3 natively, which is why it plays there.
try play audioclip "/your/path"
By the way, google can provide this information within 3 seconds:
http://lessons.runrev.com/m/4071/l/25230-play-sounds

How to play wave files in X11

Please help, I need to play wave files in X11. Is there any API in X11 like PlaySound in windows? Thanks in advance
You can use aplay, mplayer, vlc, mpg123, mpg321, etc.
For raw (non-mp3, non-compressed) wav files, simple cat should work:
cat file.wav > /dev/dsp
If you need API way to do it, this is simple example how to play wav file using ALSA API.
However, this has nothing to do with X11.

Record screen and audio then generate to one video file in java.

I am writting a program as http://www.screencast-o-matic.com/. I used applet and import jmf.jar to my project. When I use it, it couldn't get anything capture devices so it couldn't capture audio and video.
I captured screen to video but it hadn't sound. I captured sound but it hadn't video. I use jmf to merger 2 stream to video file. But it error.
Everybody can help me to resol problem. Thanks your help.
You can use Xuggle-Xuggler http://www.javacodegeeks.com/2011/02/introduction-xuggler-video-manipulation.html API which is wrapper of FFmpeg command line tool. Both are open source.

Resources