English 中文(简体)
Pygame - Access CDROM
  • 时间:2024-11-03

Pygame - Access CDROM


Previous Page Next Page  

The pygame pbrary has pygame.cdrom module that enables the program to manage playback from audio CDs and DVDs. We need to exppcitly initiapze this module for its use.


>>> import pygame
>>> pygame.cdrom.init()

The module defines all important CD class to represent the CDROM device. The constructor requires ID of CDROM drive available, starting with 0.


>>> obj=pygame.cdrom.CD(0)

The CDROM object has access to following useful functions to control the playback.

init() initiapze a cdrom drive for use
quit() uninitiapze a cdrom drive for use
play() start playing audio
stop() stop audio playback
pause() temporarily stop audio playback
resume() unpause audio playback
eject() eject or open the cdrom drive
get_busy() true if the drive is playing audio
get_paused() true if the drive is paused
get_empty() False if a cdrom is in the drive
get_numtracks() the number of tracks on the cdrom
get_track_audio() true if the cdrom track has audio data
get_track_start() start time of a cdrom track
get_track_length() length of a cdrom track

First, initiapze the object.


>>> obj.init()

To find out how many tracks are present in the current CD −


>>> obj.get_numtracks()
8

To start playing the required track, give its number to play() function.


>>> obj.play(4)

To pause, resume and stop the playback, we can use relevant functions psted above.

pygame pbrary Advertisements