Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
5131 clevermous 1
2
>
3
>
4
>CDROM Examples
5
>
6
NAME="GENERATOR"
7
CONTENT="Modular DocBook HTML Stylesheet Version 1.64
8
">
9
REL="HOME"
10
TITLE="SDL Library Documentation"
11
HREF="index.html">
12
REL="UP"
13
TITLE="Examples"
14
HREF="guideexamples.html">
15
REL="PREVIOUS"
16
TITLE="Audio Examples"
17
HREF="guideaudioexamples.html">
18
REL="NEXT"
19
TITLE="Time Examples"
20
HREF="guidetimeexamples.html">
21
>
22
CLASS="SECT1"
23
BGCOLOR="#FFF8DC"
24
TEXT="#000000"
25
LINK="#0000ee"
26
VLINK="#551a8b"
27
ALINK="#ff0000"
28
>
29
CLASS="NAVHEADER"
30
>
31
WIDTH="100%"
32
BORDER="0"
33
CELLPADDING="0"
34
CELLSPACING="0"
35
>
36
>
37
COLSPAN="3"
38
ALIGN="center"
39
>SDL Library Documentation
40
>
41
>
42
>
43
WIDTH="10%"
44
ALIGN="left"
45
VALIGN="bottom"
46
>
47
HREF="guideaudioexamples.html"
48
>Prev
49
>
50
>
51
WIDTH="80%"
52
ALIGN="center"
53
VALIGN="bottom"
54
>Chapter 4. Examples
55
>
56
WIDTH="10%"
57
ALIGN="right"
58
VALIGN="bottom"
59
>
60
HREF="guidetimeexamples.html"
61
>Next
62
>
63
>
64
>
65
>
66
ALIGN="LEFT"
67
WIDTH="100%">
68
>
69
CLASS="SECT1"
70
>
71
CLASS="SECT1"
72
>
73
NAME="GUIDECDROMEXAMPLES"
74
>CDROM Examples
75
>
76
>
77
>
78
>
79
CLASS="SECT2"
80
>
81
CLASS="SECT2"
82
>
83
NAME="AEN393"
84
>Listing CD-ROM drives
85
>
86
>
87
>
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
    }
103
>
104
>
105
>
106
CLASS="SECT2"
107
>
108
CLASS="SECT2"
109
>
110
NAME="AEN397"
111
>Opening the default drive
112
>
113
>
114
>
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
    }
152
>
153
>
154
>
155
CLASS="SECT2"
156
>
157
CLASS="SECT2"
158
>
159
NAME="AEN401"
160
>Listing the tracks on a CD
161
>
162
>
163
>
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
    }
178
>
179
>
180
>
181
CLASS="SECT2"
182
>
183
CLASS="SECT2"
184
>
185
NAME="AEN405"
186
>Play an entire CD
187
>
188
>
189
>
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);
205
>
206
>
207
>
208
>
209
CLASS="NAVFOOTER"
210
>
211
ALIGN="LEFT"
212
WIDTH="100%">
213
WIDTH="100%"
214
BORDER="0"
215
CELLPADDING="0"
216
CELLSPACING="0"
217
>
218
>
219
WIDTH="33%"
220
ALIGN="left"
221
VALIGN="top"
222
>
223
HREF="guideaudioexamples.html"
224
>Prev
225
>
226
>
227
WIDTH="34%"
228
ALIGN="center"
229
VALIGN="top"
230
>
231
HREF="index.html"
232
>Home
233
>
234
>
235
WIDTH="33%"
236
ALIGN="right"
237
VALIGN="top"
238
>
239
HREF="guidetimeexamples.html"
240
>Next
241
>
242
>
243
>
244
>
245
WIDTH="33%"
246
ALIGN="left"
247
VALIGN="top"
248
>Audio Examples
249
>
250
WIDTH="34%"
251
ALIGN="center"
252
VALIGN="top"
253
>
254
HREF="guideexamples.html"
255
>Up
256
>
257
>
258
WIDTH="33%"
259
ALIGN="right"
260
VALIGN="top"
261
>Time Examples
262
>
263
>
264
>
265
>
266
>
267
>