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.
Related
I made an app(although not finish yet)with kivy module. It can let me upload my audio file in and play it.
It works like this if I press the play button on the right corner, it will play audio file (using vlc module for mp3 and kivy SoundLoader for other types of audio file)
This app is for iPad use(although I currently test it on pc), but I don't know how to make it background playing, I mean making it can even play sound while the screen is black or while using other app on the screen like wut youtube premieum does.
This is important for me because I tried to develope this app in order to listen to my music and do my homework with ipad page meantime.
Pls tell me some method if you have any idea, thank you!
well I haven't tried much methods bc I currently didn't fine out much information.
U actually will found people talking about pygame running other function while BGM is playing (which is not wut I want) if u just search "python background playing" on search engines
I am making a simple Python utility that shows the tempo of a song (BPM) that is playing. I record short fragments of a few seconds to calculate the tempo over. The problem is that now I want to show this on a display using a Pygame UI, but when I'm recording sound, the UI does not respond. I want to make it so that the UI will stay responsive during the recording of the sound, and then update the value on the screen once the tempo over a new fragment has been calculated. How can I implement this?
I have looked at threading but I'm not sure this is the appropriate solution for this.
I'd use the python threading library.
Use the pygame module in the main thread (just the normal python shell, effectively) an create a separate thread for the function that determines BPM.
This BPM can then be saved to a global variable that can be accessed by PyGame for displaying.
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.
I am having a weird problem with VLC in Python. Using the following things.
import vlc
self.Instance = vlc.Instance()
self.List = self.Instance.media_list_new()
self.Player_d = self.Instance.media_list_player_new()
I am using self.List.add_media(address of video) to populate the media list.
Then self.Player_d.set_media_list(self.List)
and self.Player_d.play()
The problem is that VLC starts in a weird (YUV something) window, without any controls. Then freezes after playing the list. I have to use Task Manager to shut it down.
Can anybody point out the problem? I want to play the VLC with all controls.
Secondly, is there anyway of checking if VLC is already running, if running, then to quit and start a new instance of VLC.
Any help would be appreciated.
I don't see anything about wxPython in your question, but if you're using it with the vlc module, then that could be your problem. I'm guessing they don't play nicely together. You probably need to run all the vlc stuff in a separate thread rather than in wx's main loop.
I have been playing around with writing some simple card games in Python for fun and I would like to add a graphical user interface (GUI) to the games. Which library would you recommend for writing the GUI for a simple card game?
If all you want is a GUI, wxPython should do the trick.
If you're looking to add sound, controller input, and take it beyond a simple card game, then you may want to use pygame.
I haven't used wxPython, but Pygame by itself is rather low-level. It allows you to catch key presses, mouse events and draw stuff on the screen, but doesn't offer any pre-made GUI controls. If you use Pygame, you will either have to write your own GUI classes or use existing GUI extensions for Pygame, like Phil's Pygame Utilities.
Generally, PyGame is the better option for coding games. But that's for the more common type of games - where things move on the screen and you must have a good "frame-rate" performance.
For something like a card game, however, I'd go with wxPython (or rather, PyQt). This is because a card game hasn't much in terms of graphics (drawing 2D card shapes on the screen is no harder in wx / PyQt than in PyGame). And on the other hand, you get lots of benefits from wx - like a ready-made GUI for interaction.
In Pygame you have to create a GUI yourself or wade through several half-baked libraries that do it for you. This actually makes sense for Pygame because when you create a game you usually want a GUI of your own, that fits the game's style. But for card games, most chances are that wx's standard GUI widgets will do the trick and will save you hours of coding.
The answers to this related question may be very useful for you:
What can Pygame do in terms of graphics that wxPython can't?
I'd say pygame -- I've heard it's lots of fun, easy and happy. Also, all of my experiences with wxPython have been sad an painful.
But I'm not bias or anything.
pygame is the typical choice, but pyglet has been getting a lot of attention at PyCon. Here's a wiki entry on Python Game libraries: http://wiki.python.org/moin/PythonGameLibraries