Arlie wrote:
Hi,
Newbie here. I copied and pasted the code below. But when I ran it I
got this error:
D:\>python mp3.py
Duree du fichier : 298919 millisecondes
Traceback (most recent call last):
File "mp3.py", line 37, in <module>
time.sleep(int(buf)/1000)
ValueError: invalid literal for int() with base 10: ''
The code:
# -*- coding: utf-8 -*-
import time
from ctypes import windll, c_buffer
class mci:
def __init__(self):
self.w32mci = windll.winmm.mciSendStringA
self.w32mcierror = windll.winmm.mciGetErrorStringA
def send(self,commande):
buffer = c_buffer(255)
errorcode = self.w32mci(str(commande),buffer,254,0)
if errorcode:
return errorcode, self.get_error(errorcode)
else:
return errorcode,buffer.value
def get_error(self,error):
error = int(error)
buffer = c_buffer(255)
self.w32mcierror(error,buffer,254)
return buffer.value
def directsend(self, txt):
(err,buf)=self.send(txt)
if err != 0:
print'Erreur',str(err),'sur',txt,':',buf
return (err,buf)
mci=mci()
mci.directsend('open "d:\\Linger.mp3" alias toto')
mci.directsend('set toto time format milliseconds')
err,buf=mci.directsend('status toto length ')
print 'Duree du fichier : ',buf,' millisecondes'
From the output it's clear that 'buf' contains '298919'.
err,buf=mci.directsend('play toto from 0 to '+str(buf))
time.sleep(int(buf)/1000)
From the output it's clear that 'buf' contains ''. Are you expecting it
to contain the length, like it did for the previous call? Perhaps you
should just use the length returned by the previous call.
mci.directsend('close toto')
--
http://mail.python.org/mailman/listinfo/python-list