I'm having problems finding a solution to play a mp4 file with psychopy.
Should I put the file in a special folder? How can I find this folder? And is there a special function to open then the file when running the code?
I tried making a class, but I have problems when defining the path.
Please taking in consideration that I just started programming.
Probe-Code
Thanks in advance
import playsound
playsound.playsound('sample.mp3')
Process to play this song: first create a file play.mp3 and copy the path of file and paste that code on the place of sample.mp3 in your code editor.
Related
I am creating a program in Python that requires the user to place images into an Input folder, and then take images out of an Output folder. As this will become an application, the Input and Output folders will be very difficult to navigate to, being buried in the app's contents.
I am looking for a way to open folders onscreen so that a user can add or remove their own files from these folders, without knowing the exact location of the folders they are interacting with.
I am thoroughly stumped on this problem, and I appreciate all of your time.
Thank you very much.
*Edit: I am working on MacOS
If the program is intended for use on windows, it seems like you could use the solution here, where you could open explorer as a sub process and then open the path to the file.
For example
import subprocess
subprocess.Popen(r'explorer /select, FilePath')
You could also use os, and os.startfile(FilePath).
I'm searching for a solution because I'm blocked and I don't understand why.
I'm a new user of Sumo, and to make my directory much clearer and less messy, I create a New Directory in the Directory where I put all files related to the sumocfg file I was working on (net.xml and rou.xml including sumocfg)
But now when I want to open the sumocfg file, it claims that the net.xml file is not found by searching it in the older directory it was.
Here is the error brought
Errorfile
And my problem is that he is searching the net.xml file in the path "Sumo/FirstIntersection.net.xml" instead of "Sumo/FirstIntersection/FirstIntersection.net.xml"
And I don't know why because when I open a simulation, I locate the good path.
Opening Simulation
I hope I was clear in describing the problem encountered.
Have some of you encountered the same issue?
Thanks in advance for your replies.
The sumocfg file is an XML file which you can modify with your favorite text editor. In your case it probably contains an absolute path to your network, that's why it does not work. You can simply change it to a relative path though. So instead of <net-file value="/full/path/to/FirstIntersection.net.xml"/> it should read <net-file value="FirstIntersection.net.xml"/>
I'm trying to use playsound to play a file within the folder of my code, however every time I run my code it seems it is able to call the file however I always receive this output:
playsound.PlaysoundException:
Error 277 for command:
open "para.mp3" alias playsound_0.9208788744295284
A problem occurred in initializing MCI.
The code that is run is just the use of the playsound function:
from playsound import playsound
playsound("01. Humongous.mp3")
I'm unsure if this is just an issue with my machine or something that I'm missing?
Convert the mp3 file to wav. Worked for me.
Managed to fix it. After hours of ripping my hair out I eventually tried a different file to play and it worked. Not actually sure if there is a bitrate limit with the playsound library but it certainly didn't like that particular file. Tried another file with a lower bitrate and it worked fine.
I also faced the same issue it is not with the bit rate of the file, it seems to be the tags in the music file like "track title, cover art, album name, encoding" and so on is causing it so I would like to recommend you to remove these tags and leave it as such, to do this editing I used mp3tag application you can get it from here. This worked for me. You can check instructables to know how to use this application to edit tags.
If you want those tags you can type it out and check if again the problem arises if it does then don't add the tags.
Try removing the period from the filename you're playing and try again. I don't know what system you're running this on, but it might be interfering with the file reading process.
In playsound,for (.mp3)
you can't directly upload the customized mp3 file because of some issue in bit initailizaing.
To solve this issue,
We need to change our .mp3 file to .mp3 format again on some audio converter application or online converter. Now converted mp3 file can be flawlessly accessed for playsound.playsound(dir/users/converted/song.mp3).Enjoy it..
I am having problems with Project Multiclipboard from Chapter 8 of the book: Automate the Boring Stuff and using Python 3.
The first issue is that, suppose my program mcb.pyw is saved in:
C:\Users\myName\folder name
where the last folder has a space in the name, my batch file:
#pyw.exe C:\Users\myName\folder name\mcb.pyw %*
doesn't seem to work properly from the command line. I can now type in
mcb save keyword
into the command line without getting an error, but it's not doing anything. After testing by changing the directory to a folder whose path has no space in it, I've concluded that the problem is because of the space, but I am unsure of how I might go about fixing this.
The second issue is that when the batch file is working, the module shelve seems to be saving the data in the wrong folder. Specifically, I noticed that if I were to run mcb.pyw from the command line, shelve would save the data in C:\Users\myName, which is also the default directory when you open the command windod, instead of the folder C:\Users\myName\folderName, where mcb.pyw and mcb.bat are saved.
I have gotten around this by including the lines:
import os
os.chdir('C:\\Users\\myName\\folderName')
However, is there any other way to solve this issue? Why is shelve saving in C:\Users\myName instead of the folder where everything is already saved?
I apologise if I have made any ettiquette or formatting problems. If you let me know what I did wrong I will do my best to fix it as soon as I can, thank you!
Files are always saved in the current working directory unless they are specified with path names, so you do have to change your working directory if the default one is not what you want.
You can avoid hard-coding the path name and always change your working directory where the script is located with:
import os
import sys
os.chdir(os.path.dirname(sys.argv[0]))
I made a program to open files windows can't but I have to put the file everywhere I want to use it. How can I just give it a path to use to find the file to read?
Basically how would I open a file out of a program's folder?
I would think that it would be...
file = open('C://Users/Name/Python33/file','r') But that isn't working.
Could someone give me example code?
Use command line arguments:
sys.argv[...]
You can do this either through command line arguments, as suggested by #qarma, or any other kind of I/O (taking raw_input, for instance). If you're unfamiliar with accessing files by paths in Python, you may find os.path useful.