0
|
1 <HTML
|
|
2 ><HEAD
|
|
3 ><TITLE
|
|
4 >CDROM Examples</TITLE
|
|
5 ><META
|
|
6 NAME="GENERATOR"
|
|
7 CONTENT="Modular DocBook HTML Stylesheet Version 1.61
|
|
8 "><LINK
|
|
9 REL="HOME"
|
|
10 TITLE="SDL Library Documentation"
|
|
11 HREF="index.html"><LINK
|
|
12 REL="UP"
|
|
13 TITLE="Examples"
|
|
14 HREF="guideexamples.html"><LINK
|
|
15 REL="PREVIOUS"
|
|
16 TITLE="Audio Examples"
|
|
17 HREF="guideaudioexamples.html"><LINK
|
|
18 REL="NEXT"
|
|
19 TITLE="Time Examples"
|
|
20 HREF="guidetimeexamples.html"></HEAD
|
|
21 ><BODY
|
|
22 CLASS="SECT1"
|
|
23 BGCOLOR="#FFF8DC"
|
|
24 TEXT="#000000"
|
|
25 LINK="#0000ee"
|
|
26 VLINK="#551a8b"
|
|
27 ALINK="#ff0000"
|
|
28 ><DIV
|
|
29 CLASS="NAVHEADER"
|
|
30 ><TABLE
|
|
31 WIDTH="100%"
|
|
32 BORDER="0"
|
|
33 CELLPADDING="0"
|
|
34 CELLSPACING="0"
|
|
35 ><TR
|
|
36 ><TH
|
|
37 COLSPAN="3"
|
|
38 ALIGN="center"
|
|
39 >SDL Library Documentation</TH
|
|
40 ></TR
|
|
41 ><TR
|
|
42 ><TD
|
|
43 WIDTH="10%"
|
|
44 ALIGN="left"
|
|
45 VALIGN="bottom"
|
|
46 ><A
|
|
47 HREF="guideaudioexamples.html"
|
|
48 >Prev</A
|
|
49 ></TD
|
|
50 ><TD
|
|
51 WIDTH="80%"
|
|
52 ALIGN="center"
|
|
53 VALIGN="bottom"
|
|
54 >Chapter 4. Examples</TD
|
|
55 ><TD
|
|
56 WIDTH="10%"
|
|
57 ALIGN="right"
|
|
58 VALIGN="bottom"
|
|
59 ><A
|
|
60 HREF="guidetimeexamples.html"
|
|
61 >Next</A
|
|
62 ></TD
|
|
63 ></TR
|
|
64 ></TABLE
|
|
65 ><HR
|
|
66 ALIGN="LEFT"
|
|
67 WIDTH="100%"></DIV
|
|
68 ><DIV
|
|
69 CLASS="SECT1"
|
|
70 ><H1
|
|
71 CLASS="SECT1"
|
|
72 ><A
|
|
73 NAME="GUIDECDROMEXAMPLES"
|
|
74 >CDROM Examples</A
|
|
75 ></H1
|
|
76 ><P
|
|
77 ></P
|
|
78 ><DIV
|
|
79 CLASS="SECT2"
|
|
80 ><H2
|
|
81 CLASS="SECT2"
|
|
82 ><A
|
|
83 NAME="AEN354"
|
|
84 >Listing CD-ROM drives</A
|
|
85 ></H2
|
|
86 ><P
|
|
87 ><PRE
|
|
88 CLASS="PROGRAMLISTING"
|
|
89 > #include "SDL.h"
|
|
90
|
|
91 /* Initialize SDL first */
|
|
92 if ( SDL_Init(SDL_INIT_CDROM) < 0 ) {
|
|
93 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
|
|
94 exit(1);
|
|
95 }
|
|
96 atexit(SDL_Quit);
|
|
97
|
|
98 /* Find out how many CD-ROM drives are connected to the system */
|
|
99 printf("Drives available: %d\n", SDL_CDNumDrives());
|
|
100 for ( i=0; i<SDL_CDNumDrives(); ++i ) {
|
|
101 printf("Drive %d: \"%s\"\n", i, SDL_CDName(i));
|
|
102 }</PRE
|
|
103 ></P
|
|
104 ></DIV
|
|
105 ><DIV
|
|
106 CLASS="SECT2"
|
|
107 ><H2
|
|
108 CLASS="SECT2"
|
|
109 ><A
|
|
110 NAME="AEN358"
|
|
111 >Opening the default drive</A
|
|
112 ></H2
|
|
113 ><P
|
|
114 ><PRE
|
|
115 CLASS="PROGRAMLISTING"
|
|
116 > SDL_CD *cdrom;
|
|
117 CDstatus status;
|
|
118 char *status_str;
|
|
119
|
|
120 cdrom = SDL_CDOpen(0);
|
|
121 if ( cdrom == NULL ) {
|
|
122 fprintf(stderr, "Couldn't open default CD-ROM drive: %s\n",
|
|
123 SDL_GetError());
|
|
124 exit(2);
|
|
125 }
|
|
126
|
|
127 status = SDL_CDStatus(cdrom);
|
|
128 switch (status) {
|
|
129 case CD_TRAYEMPTY:
|
|
130 status_str = "tray empty";
|
|
131 break;
|
|
132 case CD_STOPPED:
|
|
133 status_str = "stopped";
|
|
134 break;
|
|
135 case CD_PLAYING:
|
|
136 status_str = "playing";
|
|
137 break;
|
|
138 case CD_PAUSED:
|
|
139 status_str = "paused";
|
|
140 break;
|
|
141 case CD_ERROR:
|
|
142 status_str = "error state";
|
|
143 break;
|
|
144 }
|
|
145 printf("Drive status: %s\n", status_str);
|
|
146 if ( status >= CD_PLAYING ) {
|
|
147 int m, s, f;
|
|
148 FRAMES_TO_MSF(cdrom->cur_frame, &m, &s, &f);
|
|
149 printf("Currently playing track %d, %d:%2.2d\n",
|
|
150 cdrom->track[cdrom->cur_track].id, m, s);
|
|
151 }</PRE
|
|
152 ></P
|
|
153 ></DIV
|
|
154 ><DIV
|
|
155 CLASS="SECT2"
|
|
156 ><H2
|
|
157 CLASS="SECT2"
|
|
158 ><A
|
|
159 NAME="AEN362"
|
|
160 >Listing the tracks on a CD</A
|
|
161 ></H2
|
|
162 ><P
|
|
163 ><PRE
|
|
164 CLASS="PROGRAMLISTING"
|
|
165 > SDL_CD *cdrom; /* Assuming this has already been set.. */
|
|
166 int i;
|
|
167 int m, s, f;
|
|
168
|
|
169 SDL_CDStatus(cdrom);
|
|
170 printf("Drive tracks: %d\n", cdrom->numtracks);
|
|
171 for ( i=0; i<cdrom->numtracks; ++i ) {
|
|
172 FRAMES_TO_MSF(cdrom->track[i].length, &m, &s, &f);
|
|
173 if ( f > 0 )
|
|
174 ++s;
|
|
175 printf("\tTrack (index %d) %d: %d:%2.2d\n", i,
|
|
176 cdrom->track[i].id, m, s);
|
|
177 }</PRE
|
|
178 ></P
|
|
179 ></DIV
|
|
180 ><DIV
|
|
181 CLASS="SECT2"
|
|
182 ><H2
|
|
183 CLASS="SECT2"
|
|
184 ><A
|
|
185 NAME="AEN366"
|
|
186 >Play an entire CD</A
|
|
187 ></H2
|
|
188 ><P
|
|
189 ><PRE
|
|
190 CLASS="PROGRAMLISTING"
|
|
191 > SDL_CD *cdrom; /* Assuming this has already been set.. */
|
|
192
|
|
193 // Play entire CD:
|
|
194 if ( CD_INDRIVE(SDL_CDStatus(cdrom)) )
|
|
195 SDL_CDPlayTracks(cdrom, 0, 0, 0, 0);
|
|
196
|
|
197 // Play last track:
|
|
198 if ( CD_INDRIVE(SDL_CDStatus(cdrom)) ) {
|
|
199 SDL_CDPlayTracks(cdrom, cdrom->numtracks-1, 0, 0, 0);
|
|
200 }
|
|
201
|
|
202 // Play first and second track and 10 seconds of third track:
|
|
203 if ( CD_INDRIVE(SDL_CDStatus(cdrom)) )
|
|
204 SDL_CDPlayTracks(cdrom, 0, 0, 2, 10);</PRE
|
|
205 ></P
|
|
206 ></DIV
|
|
207 ></DIV
|
|
208 ><DIV
|
|
209 CLASS="NAVFOOTER"
|
|
210 ><HR
|
|
211 ALIGN="LEFT"
|
|
212 WIDTH="100%"><TABLE
|
|
213 WIDTH="100%"
|
|
214 BORDER="0"
|
|
215 CELLPADDING="0"
|
|
216 CELLSPACING="0"
|
|
217 ><TR
|
|
218 ><TD
|
|
219 WIDTH="33%"
|
|
220 ALIGN="left"
|
|
221 VALIGN="top"
|
|
222 ><A
|
|
223 HREF="guideaudioexamples.html"
|
|
224 >Prev</A
|
|
225 ></TD
|
|
226 ><TD
|
|
227 WIDTH="34%"
|
|
228 ALIGN="center"
|
|
229 VALIGN="top"
|
|
230 ><A
|
|
231 HREF="index.html"
|
|
232 >Home</A
|
|
233 ></TD
|
|
234 ><TD
|
|
235 WIDTH="33%"
|
|
236 ALIGN="right"
|
|
237 VALIGN="top"
|
|
238 ><A
|
|
239 HREF="guidetimeexamples.html"
|
|
240 >Next</A
|
|
241 ></TD
|
|
242 ></TR
|
|
243 ><TR
|
|
244 ><TD
|
|
245 WIDTH="33%"
|
|
246 ALIGN="left"
|
|
247 VALIGN="top"
|
|
248 >Audio Examples</TD
|
|
249 ><TD
|
|
250 WIDTH="34%"
|
|
251 ALIGN="center"
|
|
252 VALIGN="top"
|
|
253 ><A
|
|
254 HREF="guideexamples.html"
|
|
255 >Up</A
|
|
256 ></TD
|
|
257 ><TD
|
|
258 WIDTH="33%"
|
|
259 ALIGN="right"
|
|
260 VALIGN="top"
|
|
261 >Time Examples</TD
|
|
262 ></TR
|
|
263 ></TABLE
|
|
264 ></DIV
|
|
265 ></BODY
|
|
266 ></HTML
|
|
267 > |