playcd.py :  » Mobile » Python-for-PalmOS » Python-1.5.2+reduced-1.0 » Demo » sgi » cd » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Mobile » Python for PalmOS 
Python for PalmOS » Python 1.5.2 reduced 1.0 » Demo » sgi » cd » playcd.py
# Play CD audio on speaker or headphones.

callbacktypes = ['audio','pnum','index','ptime','atime','catalog','ident','control']

def playaudio(port, type, audio):
  port.writesamps(audio)

def prtrack(cdinfo, type, pnum):
  if cdinfo.track[pnum] <> '':
    print 'playing "' + cdinfo.track[pnum] + '"'
  else:
    print callbacktypes[type]+': '+`pnum`

def callback(arg, type, data):
  print callbacktypes[type]+': '+`data`

def tcallback(arg, type, data):
  print callbacktypes[type]+': '+triple(data)

def triple((a, b, c)):
  return zfill(a) + ':' + zfill(b) + ':' + zfill(c)

def zfill(n):
  s = `n`
  return '0' * (2 - len(s)) + s

def prtrackinfo(info):
  for i in range(len(info)):
    start, total = info[i]
    print 'Track', zfill(i+1), triple(start), triple(total)

statedict = ['ERROR', 'NODISK', 'READY', 'PLAYING', 'PAUSED', 'STILL']

def prstatus(status):
  state, track, curtime, abstime, totaltime, first, last, \
    scsi_audio, cur_block, dummy = status
  print 'Status:',
  if 0 <= state < len(statedict):
    print statedict[state]
  else:
    print state
  print 'Track: ', track
  print 'Time:  ', triple(curtime)
  print 'Abs:   ', triple(abstime)
  print 'Total: ', triple(totaltime)
  print 'First: ', first
  print 'Last:  ', last
  print 'SCSI:  ', scsi_audio
  print 'Block: ', cur_block
  print 'Future:', dummy

def main():
  import sys, readcd, al, AL, cd, cdplayer
  verbose = 0
  r = readcd.Readcd()
  prstatus(r.getstatus())
  prtrackinfo(r.gettrackinfo())
  cdinfo = cdplayer.Cdplayer(r.gettrackinfo())
  if cdinfo.title <> '':
    print 'Title: "' + cdinfo.title + '"'
  if cdinfo.artist <> '':
    print 'Artist: ' + cdinfo.artist
  for arg in sys.argv[1:]:
    if arg == '-v':
      verbose = 1
      continue
    x = eval(arg)
    try:
      l = len(x)
      r.appendstretch(x[0], x[1])
    except TypeError:
      r.appendtrack(x)
  try:
    oldparams = [AL.OUTPUT_RATE, 0]
    params = oldparams[:]
    al.getparams(AL.DEFAULT_DEVICE, oldparams)
    params[1] = AL.RATE_44100
    al.setparams(AL.DEFAULT_DEVICE, params)
    config = al.newconfig()
    config.setwidth(AL.SAMPLE_16)
    config.setchannels(AL.STEREO)
    port = al.openport('CD Player', 'w', config)

    for i in range(8):
      r.setcallback(i, callback, None)
    if verbose:
      r.setcallback(cd.ptime, tcallback, None)
      r.setcallback(cd.atime, tcallback, None)
    else:
      r.removecallback(cd.ptime)
      r.removecallback(cd.atime)
    r.setcallback(cd.pnum, prtrack, cdinfo)
    r.setcallback(cd.audio, playaudio, port)

    data = r.play()
  except KeyboardInterrupt:
    status = r.getstatus()
    print 'Interrupted at '+triple(status[2])+' into track '+ \
        `status[1]`+' (absolute time '+triple(status[3])+')'
  al.setparams(AL.DEFAULT_DEVICE, oldparams)

main()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.