1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
|
.. include:: common.txt
:mod:`pygame.cdrom`
===================
.. module:: pygame.cdrom
:synopsis: pygame module for audio cdrom control
| :sl:`pygame module for audio cdrom control`
.. warning::
This module is non functional in pygame 2.0 and above, unless you have manually compiled pygame with SDL1.
This module will not be supported in the future.
One alternative for python cdrom functionality is `pycdio <https://pypi.org/project/pycdio/>`_.
The cdrom module manages the ``CD`` and ``DVD`` drives on a computer. It can
also control the playback of audio CDs. This module needs to be initialized
before it can do anything. Each ``CD`` object you create represents a cdrom
drive and must also be initialized individually before it can do most things.
.. function:: init
| :sl:`initialize the cdrom module`
| :sg:`init() -> None`
Initialize the cdrom module. This will scan the system for all ``CD``
devices. The module must be initialized before any other functions will
work. This automatically happens when you call ``pygame.init()``.
It is safe to call this function more than once.
.. ## pygame.cdrom.init ##
.. function:: quit
| :sl:`uninitialize the cdrom module`
| :sg:`quit() -> None`
Uninitialize the cdrom module. After you call this any existing ``CD``
objects will no longer work.
It is safe to call this function more than once.
.. ## pygame.cdrom.quit ##
.. function:: get_init
| :sl:`true if the cdrom module is initialized`
| :sg:`get_init() -> bool`
Test if the cdrom module is initialized or not. This is different than the
``CD.init()`` since each drive must also be initialized individually.
.. ## pygame.cdrom.get_init ##
.. function:: get_count
| :sl:`number of cd drives on the system`
| :sg:`get_count() -> count`
Return the number of cd drives on the system. When you create ``CD`` objects
you need to pass an integer id that must be lower than this count. The count
will be 0 if there are no drives on the system.
.. ## pygame.cdrom.get_count ##
.. class:: CD
| :sl:`class to manage a cdrom drive`
| :sg:`CD(id) -> CD`
You can create a ``CD`` object for each cdrom on the system. Use
``pygame.cdrom.get_count()`` to determine how many drives actually exist.
The id argument is an integer of the drive, starting at zero.
The ``CD`` object is not initialized, you can only call ``CD.get_id()`` and
``CD.get_name()`` on an uninitialized drive.
It is safe to create multiple ``CD`` objects for the same drive, they will
all cooperate normally.
.. method:: init
| :sl:`initialize a cdrom drive for use`
| :sg:`init() -> None`
Initialize the cdrom drive for use. The drive must be initialized for
most ``CD`` methods to work. Even if the rest of pygame has been
initialized.
There may be a brief pause while the drive is initialized. Avoid
``CD.init()`` if the program should not stop for a second or two.
.. ## CD.init ##
.. method:: quit
| :sl:`uninitialize a cdrom drive for use`
| :sg:`quit() -> None`
Uninitialize a drive for use. Call this when your program will not be
accessing the drive for awhile.
.. ## CD.quit ##
.. method:: get_init
| :sl:`true if this cd device initialized`
| :sg:`get_init() -> bool`
Test if this ``CDROM`` device is initialized. This is different than the
``pygame.cdrom.init()`` since each drive must also be initialized
individually.
.. ## CD.get_init ##
.. method:: play
| :sl:`start playing audio`
| :sg:`play(track, start=None, end=None) -> None`
Playback audio from an audio cdrom in the drive. Besides the track number
argument, you can also pass a starting and ending time for playback. The
start and end time are in seconds, and can limit the section of an audio
track played.
If you pass a start time but no end, the audio will play to the end of
the track. If you pass a start time and 'None' for the end time, the
audio will play to the end of the entire disc.
See the ``CD.get_numtracks()`` and ``CD.get_track_audio()`` to find
tracks to playback.
Note, track 0 is the first track on the ``CD``. Track numbers start at
zero.
.. ## CD.play ##
.. method:: stop
| :sl:`stop audio playback`
| :sg:`stop() -> None`
Stops playback of audio from the cdrom. This will also lose the current
playback position. This method does nothing if the drive isn't already
playing audio.
.. ## CD.stop ##
.. method:: pause
| :sl:`temporarily stop audio playback`
| :sg:`pause() -> None`
Temporarily stop audio playback on the ``CD``. The playback can be
resumed at the same point with the ``CD.resume()`` method. If the ``CD``
is not playing this method does nothing.
Note, track 0 is the first track on the ``CD``. Track numbers start at
zero.
.. ## CD.pause ##
.. method:: resume
| :sl:`unpause audio playback`
| :sg:`resume() -> None`
Unpause a paused ``CD``. If the ``CD`` is not paused or already playing,
this method does nothing.
.. ## CD.resume ##
.. method:: eject
| :sl:`eject or open the cdrom drive`
| :sg:`eject() -> None`
This will open the cdrom drive and eject the cdrom. If the drive is
playing or paused it will be stopped.
.. ## CD.eject ##
.. method:: get_id
| :sl:`the index of the cdrom drive`
| :sg:`get_id() -> id`
Returns the integer id that was used to create the ``CD`` instance. This
method can work on an uninitialized ``CD``.
.. ## CD.get_id ##
.. method:: get_name
| :sl:`the system name of the cdrom drive`
| :sg:`get_name() -> name`
Return the string name of the drive. This is the system name used to
represent the drive. It is often the drive letter or device name. This
method can work on an uninitialized ``CD``.
.. ## CD.get_name ##
.. method:: get_busy
| :sl:`true if the drive is playing audio`
| :sg:`get_busy() -> bool`
Returns True if the drive busy playing back audio.
.. ## CD.get_busy ##
.. method:: get_paused
| :sl:`true if the drive is paused`
| :sg:`get_paused() -> bool`
Returns True if the drive is currently paused.
.. ## CD.get_paused ##
.. method:: get_current
| :sl:`the current audio playback position`
| :sg:`get_current() -> track, seconds`
Returns both the current track and time of that track. This method works
when the drive is either playing or paused.
Note, track 0 is the first track on the ``CD``. Track numbers start at
zero.
.. ## CD.get_current ##
.. method:: get_empty
| :sl:`False if a cdrom is in the drive`
| :sg:`get_empty() -> bool`
Return False if there is a cdrom currently in the drive. If the drive is
empty this will return True.
.. ## CD.get_empty ##
.. method:: get_numtracks
| :sl:`the number of tracks on the cdrom`
| :sg:`get_numtracks() -> count`
Return the number of tracks on the cdrom in the drive. This will return
zero of the drive is empty or has no tracks.
.. ## CD.get_numtracks ##
.. method:: get_track_audio
| :sl:`true if the cdrom track has audio data`
| :sg:`get_track_audio(track) -> bool`
Determine if a track on a cdrom contains audio data. You can also call
``CD.num_tracks()`` and ``CD.get_all()`` to determine more information
about the cdrom.
Note, track 0 is the first track on the ``CD``. Track numbers start at
zero.
.. ## CD.get_track_audio ##
.. method:: get_all
| :sl:`get all track information`
| :sg:`get_all() -> [(audio, start, end, length), ...]`
Return a list with information for every track on the cdrom. The
information consists of a tuple with four values. The audio value is True
if the track contains audio data. The start, end, and length values are
floating point numbers in seconds. Start and end represent absolute times
on the entire disc.
.. ## CD.get_all ##
.. method:: get_track_start
| :sl:`start time of a cdrom track`
| :sg:`get_track_start(track) -> seconds`
Return the absolute time in seconds where at start of the cdrom track.
Note, track 0 is the first track on the ``CD``. Track numbers start at
zero.
.. ## CD.get_track_start ##
.. method:: get_track_length
| :sl:`length of a cdrom track`
| :sg:`get_track_length(track) -> seconds`
Return a floating point value in seconds of the length of the cdrom
track.
Note, track 0 is the first track on the ``CD``. Track numbers start at
zero.
.. ## CD.get_track_length ##
.. ## pygame.cdrom.CD ##
.. ## pygame.cdrom ##
|