[Tutor] playing mp3 files
Kirk Bailey
kbailey at howlermonkey.net
Thu Dec 20 16:35:23 CET 2012
Ok, I found something that works reliably:
http://www.mailsend-online.com/blog/play-mp3-files-with-python-on-windows.html
Here is the code as modified for my uses (beware text wrap!):
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#!c:\Python25\pythonw.exe
# Copyright (c) 2011 by James K. Lawless
# jimbo at radiks.net http://www.mailsend-online.com
# License: MIT / X11
# See: http://www.mailsend-online.com/license.php
# for full license details.
#
from ctypes import *;
import os, os.path, sys
import cgitb; cgitb.enable()
#
print "Content-Type: text/html \n"
print "<html><head><title>Robot Radio Station WHEN</title></head>"
print '<body bgcolor="white" text="black" links="blue">'
print '<center><h2>Robot Radio Station WHEN</h2><br>'
#
winmm = windll.winmm
#
def mciSend(s):
i=winmm.mciSendStringA(s,0,0,0)
if i<>0:
print "Error %d in mciSendString %s" % ( i, s )
#
def playMP3(mp3Name):
mciSend("Close All")
mciSend("Open \"%s\" Type MPEGVideo Alias theMP3" % mp3Name)
mciSend("Play theMP3 Wait")
mciSend("Close theMP3")
#
mp3file="Burns Allen 400529 Sweeping into Office.mp3" # test code.
os.chdir("./RadioStation_WHEN/1") # test code. dir management will
replace.
print "playing",mp3file,"@ strftime("%a, %d %b %Y %H:%M:%S",gmtime())<p>"
# Above Logs to the console screen what is played and when
playMP3(mp3file)
# Above plays a file named in the variable -mp3file-
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
The close all does not work. Run it again, it plays the file again, OVER
the one already playing. Any input?
--
-Shaboom.
Kirk Bailey
CEO, Freehold Marketing LLC
http://www.OneBuckHosting.com/
Fnord!
More information about the Tutor
mailing list