Python Random Audio - python

I have no experience working with audio, and I am looking for some direction on where I could find music that when a button is clicked in python it will play a random song from a selection of some. I have already written a program for my aunt, and I am trying to add audio to the program. She is a devout catholic, and I would like to use catholic songs. I have spent the past hour searching for information on python audio but have not found anything of use. Any help is greatly appreciated.

Probably the easiest way to play music is to use Pygame. It has two modules that are related to playing music which are pygame.mixer and pygame.music. Here is the link to the Pygame music module. Also you can look at This thread where people discuss their recommendations for Python and music.

Related

Python to interact with Youtube

I have started learning how to code in python and so far I've been doing normal exercises and I have an idea using which I want to explore more on python. It goes something like this.
User is listening to music on his computer using some media player.
If he/she plays any video on YouTube, then the music on his computer must be paused. And when the video is completed, the music should resume.
I'm not asking for code, obviously. I just want to know what concepts should I look into for accomplishing this task.
And I am sure there will be someone who have already made this. I am just trying to make this so that I can learn some different concepts in Python.
Edit:: After looking at the comments, I am making some changes to my question and tags. I want to do this application with this particular setup - Chrome browser - Windows Media Player - Windows 8
Is this a good enough task for a beginner to use as an excuse to learn Python?
Thanks in advance!!

Video player creation in python

I need to create a widget that will play two synchronized (H264) videos, among other things. I have never done any GUI stuff before and would like to accomplish my goal with the least amount of work. I have two questions:
Do Tkinter or Qt have functionality that allows me play videos synchronously?
I have looked at both Tkinter and Qt and it seems there is no easy, built in, way to do so. But, then again, I am pretty unfamiliar with these systems so I could have overlooked something.
I'm not sure on the synchronous video side, but this related post may help understand more about potential limitation regarding video in tkinter
Way to play video files in Tkinter?
Hope this a helpful...gl
Qt lets you play videos using the QVideoWidget and QMediaPlayer. There's an example player for PyQt.
For Tkinter there is no default widget for playing videos. You can play videos with tkinter, but this is not using one of the tkinter widgets and a bit hackish. See this answer on stackoverflow
Synchronizing is tricky with videos, but possible. You would have to set the videos to start at the exact same time, with the same frame rate.

Python: Playing a music in the background?

I am currently making a game in Python. I am not using PyGame, just the console (non-GUI)
When you start the game, you will get the logo to the game, and a lot of information about the "journey" you just started. There is a lot of text, so while the text is scrolling, I want to have a song played in the background.
I start the music with the following code:
def new_game():
import winsound
winsound.PlaySound("intro.wav", winsound.SND_ALIAS)
LVL1_INTRO()
The only problem is: it won't continue to LVL1_INTRO() until the music have stopped playing. It's a problem, as the music is approximately 1-2 minutes long.
Is there any way to fix this? After the music have started, it will continue with LVL1_INTRO()
If it is possible, I would be happy if there is a code for stopping the music as well, so I don't need to start cutting the music, and make it exactly the same lenght as the intro.
Thank you very much!
According to the documentation you use the SND_ASYNC flag.
winsound.SND_ASYNC
Return immediately, allowing sounds to play asynchronously.
To stop playing, call PlaySound with a NONE argument.
winsound.PlaySound(None, winsound.SND_ASYNC)
I don't have experience with this module, but it looks as though you can play sounds asynchronously. See http://docs.python.org/2/library/winsound.html and look at SND_ASYNC.

wx.Media volume reset problems

Am working on a media player application using wx.Media but the big challenge that i am having is that the SetVolume(new_volume) of the media ctrl method is not working properly but it mutes the sound when the new_volume reaches to 0..
The new_volume is from a volume slider control. so what is the best strategy to handle this?
any sample code will be highly appreciated?
Thanks.
I created a really simple MP3 player using wx.media that I blogged about a while ago. It might help you figure this out: http://www.blog.pythonlibrary.org/2010/04/20/wxpython-creating-a-simple-mp3-player/
There's also a cool 3rd party widget that wraps mplayer that I used too: http://www.blog.pythonlibrary.org/2010/07/24/wxpython-creating-a-simple-media-player/
It's more complicated, but it plays video back more reliably. Anyway, hopefully those will get you started at least.

Python/Tkinter Audio Player

I'm developing a media player. Right now it's a simple window with a button to load .wav files. The problem is I would like to implement a pause button now. But, when playing a audio file the GUI isn't accessible again (no buttons can be pushed) till the file is done playing. How can I make the GUI dynamic while an audio file is playing?
I'm using PyAudio, and their implementation doesn't allow this.
Probably you have to use threads for that. You have to play your audio file in a different thread than the gui mainloop so that the GUI keeps responding user input.
IMHO, wxpython is not so complicated and has some utility functions that would help to do what you want. Check the wxpython demo, you have several examples there.
You can alternatively use pygame mixer for the purpose , I made the same in pyqt and I did'nt require to implement threading . You can get the documentation of pygame mixer at https://www.pygame.org/docs/ref/mixer.html
Happy Coding .
Try this out:
Check the code https://drive.google.com/file/d/0B7ccI33Aew5fNVhwZ2puYTBuUFU/view?usp=sharing
I have used pygame also.Hope this helps.

Categories

Resources