概述
# -*- coding: utf-8 -*-
#auth:liyzh
import sys
import time
lyric={"00:00":u"还记得许多年前的春天","00:04":u"那时的我还没剪去长发",
"00:08":u"没有信用卡也没有她","00:12":u"没有24小时热水的家",
"00:16":u"可当初的我是那么快乐","00:20":u"虽然只有一把破木吉他",
"00:24":u"在街上在桥下在田野中","00:28":u"唱着那无人问津的歌谣",
"00:32":u"如果有一天我老无所依","00:40":u"请把我留在在那时光里",
"00:48":u"如果有一天我悄然离去","00:56":u"请把我埋在这春天里",
"01:05":u"还记得那些寂寞的春天","01:09":u"那时的我还没留起胡须",
"01:13":u"没有情人节也没有礼物","01:17":u"没有我那可爱的小公主",
"01:21":u"可我觉得一切没那么糟","01:25":u"虽然我只有对爱的幻想",
"01:29":u"在清晨在夜晚在风中","01:33":u"唱着那无人问津的歌谣",
"01:37":u"也许有一天我老无所依","01:45":u"请把我留在在那时光里",
"01:53":u"如果有一天我悄然离去","02:01":u"请把我埋在这春天里","02:09":u"春天里",
"02:41":u"凝视着此刻烂漫的春天","02:45":u"依然象那时温暖的模样",
"02:49":u"我剪去长发留起了胡须","02:53":u"曾经的苦痛都随风而去",
"02:57":u"可我感觉却是那么悲伤","03:01":u"岁月留给我更深的迷惘",
"03:05":u"在这阳光明媚的春天里","03:09":u"我的眼泪忍不住的流淌",
"03:13":u"也许有一天我老无所依","03:21":u"请把我留在在那时光里",
"03:29":u"如果有一天我悄然离去","03:37":u"请把我埋在这春天里",
"03:45":u"如果有一天我老无所依","03:53":u"请把我留在在这春天里",
"04:01":u"如果有一天我悄然离去","04:09":u"请把我埋在这春天里","04:18":u"春天里"
}
EMULATE=0
def aplayer( name, card, rate, tt ):
import pymedia.muxer as muxer, pymedia.audio.acodec as acodec, pymedia.audio.sound as sound
import time
dm= muxer.Demuxer( str.split( name, '.' )[ -1 ].lower() )
snds= sound.getODevices()
if card not in range( len( snds ) ):
raise 'Cannot play sound to non existent device %d out of %d' % ( card+ 1, len( snds ) )
f= open( name, 'rb' )
snd= resampler= dec= None
s= f.read( 32000 )
t= 0
value = ""
start = time.clock()
while len( s ):
#print linecache.getline('spring.txt', int(random.random()*47))
dd = time.clock()-start
if(dd<60):
key = "00:%02.f" % dd
if lyric.get(key)!=None:
if lyric.get(key)!=value:
print "........"+lyric.get(key)+"......../n"
value = lyric.get(key)
else:
ss = int(dd/60)
mm = dd%60
key = "%02d:%02.f" % (ss,mm)
if lyric.get(key)!=None:
if lyric.get(key)!=value:
print "........"+lyric.get(key)+"......../n"
value = lyric.get(key)
frames= dm.parse( s )
if frames:
for fr in frames:
# Assume for now only audio streams
if dec== None:
#print dm.getHeaderInfo(), dm.streams
dec= acodec.Decoder( dm.streams[ fr[ 0 ] ] )
r= dec.decode( fr[ 1 ] )
if r and r.data:
if snd== None:
#print 'Opening sound with %d channels -> %s' % ( r.channels, snds[ card ][ 'name' ] )
snd= sound.Output( int( r.sample_rate* rate ), r.channels, sound.AFMT_S16_LE, card )
if rate< 1 or rate> 1:
resampler= sound.Resampler( (r.sample_rate,r.channels), (int(r.sample_rate/rate),r.channels) )
print 'Sound resampling %d->%d' % ( r.sample_rate, r.sample_rate/rate )
data= r.data
if resampler:
data= resampler.resample( data )
if EMULATE:
# Calc delay we should wait to emulate snd.play()
d= len( data )/ float( r.sample_rate* r.channels* 2 )
time.sleep( d )
if int( t+d )!= int( t ):
print 'playing: %d sec/r' % ( t+d ),
t+= d
else:
snd.play( data )
if tt> 0:
if snd and snd.getPosition()> tt:
break
s= f.read( 512 )
while snd.isPlaying():
time.sleep( .05 )
while(True):
aplayer("spring.mp3",0,1,-1)
最后
以上就是有魅力花卷为你收集整理的python实现的dos窗口播放器的全部内容,希望文章能够帮你解决python实现的dos窗口播放器所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复