Eseguire un CDROM mediante le funzioni del API di SDL

Da Gambas-it.org - Wikipedia.

La libreria SDL ci permette di eseguire il contenuto audio di un CDROM.

Le funzioni, utili per gestire il CDROM, nella versione obsoleta, ma ancora funzionante, "libSDL-1.2:1.2.68 ".

Mostriamo un semplice esempio pratico:

Library "libSDL-1.2:1.2.68"

Private Const SDL_INIT_CDROM As Integer = &h100
Private Enum CD_TRAYEMPTY, CD_STOPPED, CD_PLAYING, CD_PAUSED, CD_ERROR = -1

' int SDL_Init(Uint32 flags)
' Initialize the SDL library.
Private Extern SDL_Init(flags As Integer) As Integer

' int SDL_CDNumDrives(void)
' Returns the number of CD-ROM drives on the system.
Private Extern SDL_CDNumDrives() As Integer

' SDL_CD *SDL_CDOpen(int drive)
' Opens a CD-ROM drive for access.
Private Extern SDL_CDOpen(drive As Integer) As Pointer

' CDstatus SDL_CDStatus(SDL_CD *cdrom)
' Returns the current status of the given drive.
Private Extern SDL_CDStatus(cdrom As Pointer) As Integer

' int SDL_CDPlayTracks(SDL_CD *cdrom, int start_track, int start_frame, int ntracks, int nframes))
' SDL_CDPlayTracks plays the given CD starting at track start_track, for ntracks tracks.
Private Extern SDL_CDPlayTracks(cdrom As Pointer, start_track As Integer, start_frame As Integer, ntracks As Integer, nframes As Integer) As Integer

 ' void SDL_Delay(Uint32 ms)
' Wait a specified number of milliseconds before returning.
Private Extern SDL_Delay(ms As Integer)

' void SDL_CDClose(SDL_CD *cdrom)
' Closes the given cdrom handle.
Private Extern SDL_CDClose(cdrom As Pointer)

' void SDL_Quit(void)
' Shuts down all SDL subsystems and frees the resources allocated to them.
Private Extern SDL_Quit()


Public Sub Main()

 Dim cd As Pointer
 
 SDL_Init(SDL_INIT_CDROM)
 
 If SDL_CDNumDrives() == 0 Then 
   Print "Nessun Driver CDRom connesso !"
   Chiusura()
 Endif
 
 cd = SDL_CDOpen(0)
 If cd == 0 Then 
   Print "Impossibile aprire il CD-Rom !"
   Chiusura()
 Endif

' Esegue l'intero CDRom.
' (Se si vuole eseguire una traccia determinata, si porrà il numero della sua posizione nel 4° argomento della seguente funzione).
 If SDL_CDStatus(cd) == CD_STOPPED Then SDL_CDPlayTracks(cd, 0, 0, 0, 0)

 While SDL_CDStatus(cd) == CD_PLAYING
   SDL_Delay(10)
 Wend

 SDL_CDClose(cd)

 Chiusura()

End


Private Procedure Chiusura()
 
 SDL_Quit()
 Quit
 
End


Riferimenti