Pygame 简明教程

Pygame - Access CDROM

pygame 库具有 pygame.cdrom 模块,该模块使程序能够管理从音频 CD 和 DVD 进行的播放。我们需要显式地初始化此模块才能使用它。

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

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

该模块定义了所有重要的 CD 类来表示 CDROM 设备。构造函数需要可用的 CDROM 驱动器的 ID,从 0 开始。

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)

CDROM 对象可以访问以下有用的函数来控制播放。

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

init()

initialize a cdrom drive for use

quit()

uninitialize 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, initialize the object.

>>> obj.init()

若要找出当前 CD 中出现的音轨数量 -

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

>>> obj.get_numtracks()
8

若要开始播放所需的音轨,将其编号给予 play() 函数。

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 listed above.

pygame library