---
name: "SDL::CD"
section: "3pm"
platform: "linux"
package: "libsdl-perl"
version: "2.548-5+b1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/SDL::CD"
---

# SDL::CD(3pm)

## NAME

SDL::CD -- SDL Bindings for structure SDL\_CD

## CATEGORY

Core, CDROM, Structure

## SYNOPSIS

```
 use SDL;
 use SDL::CDROM;
 use SDL::CD;
 SDL::init(SDL_INIT_CDROM);
 my $drives = SDL::CDROM::num_drives;

 if( $drives > 0 )
 {
  my $CD = SDL::CD->new( 0 );

   if($CD)
   {
        ...
   }

 }
```

## CONSTANTS

The constants are exported by default. You can avoid this by doing:

```
 use SDL::CD ();
```

and access them directly:

```
 SDL::CD::CD_TRAYEMPTY;
```

or by choosing the export tags below:

Export tag: ':status'

```
 CD_TRAYEMPTY
 CD_STOPPED
 CD_PLAYING
 CD_PAUSED
 CD_ERROR
```

Export tag: ':defaults'

```
 CD_FPS
 SDL_MAX_TRACKS
```

## METHOD

### new

```
 my $CD = SDL::CD->new($drive)
```

Makes a new SDL::CD object. Returns `"undef"` if the drive is busy or inaccessible.

### status

```
 my $status = $CD->status();
```

Returns the current status of the CD tray

Returns on of the following constants:

- •

  CD\_TRAYEMPTY

- •

  CD\_STOPPED

- •

  CD\_PLAYING

- •

  CD\_PAUSED

- •

  CD\_ERROR

### play\_tracks

```
 $CD->play_tracks($start_track, $start_frame, $ntracks, $nframes)
```

Plays the given SDL::CD starting at track `$start_track`, for `$ntracks` tracks.

`$start_frame` is the frame offset, from the beginning of the `$start_track`, at which to start. `$nframes` is the frame offset, from the  beginning of the last track ($start\_track+$ntracks), at which to end playing.

**play\_tracks()** should only be called after calling "status" to get information about the CD.

**Note: Data tracks are ignored.**

Returns `0`, or `-1` if there was an error.

### play

```
 $CD->play($start, $length);
```

Plays the given SDL::CD , starting a frame `$start` for `$length` frames.

Returns `0` on success, `-1` on error

### pause

```
 $CD->pause();
```

Pauses play on CD

Returns `0` on success, or `-1` on an error.

### resume

```
 $CD->resume();
```

Returns `0` on success, or `-1` on an error.

### stop

```
 $CD->stop();
```

Stops play on the CD.

Returns `0` on success, or `-1` on an error.

### eject

```
 $CD->eject();
```

Ejects the CD.

Returns `0` on success, or `-1` on an error.

### id

```
 $CD->id();
```

Private drive identifier

### num\_tracks

```
 $CD->num_tracks();
```

Number of tracks on the CD

### cur\_track

```
 $CD->cur_track();
```

Current track on the CD;

### track

```
 my $track =  $CD->track($number);
```

Retrieves track description of track `$number` in CD. See SDL::CDTrack.

### FRAMES\_TO\_MSF

```
 my ($min, $sec, $fra) = FRAMES_TO_MSF($frames);
```

Conversion functions from frames to Minute/Second/Frames

### MSF\_TO\_FRAMES

```
 my $frames = MSF_TO_FRAMES($min, $sec, $fra);
```

## SEE ALSO

SDL::CDROM, SDL::CDTrack

## AUTHORS

See "AUTHORS" in SDL.
