d7040162aa231bd703707463b6b4a074cdda5389
[platform/upstream/libvorbis.git] / doc / vorbisfile / seeking_example_c.html
1 <html>
2
3 <head>
4 <title>vorbisfile - seeking_test.c</title>
5 <link rel=stylesheet href="style.css" type="text/css">
6 </head>
7
8 <body bgcolor=white text=black link="#5555ff" alink="#5555ff" vlink="#5555ff">
9 <table border=0 width=100%>
10 <tr>
11 <td><p class=tiny>Vorbisfile documentation</p></td>
12 <td align=right><p class=tiny>vorbisfile version 1.3.2 - 20101101</p></td>
13 </tr>
14 </table>
15
16 <h1>seeking_test.c</h1>
17
18 <p>
19 The example program source:
20
21 <br><br>
22 <table border=0 width=100% color=black cellspacing=0 cellpadding=7>
23 <tr bgcolor=#cccccc>
24         <td>
25 <pre><b>
26
27 #include &lt;stdlib.h&gt;
28 #include &lt;stdio.h&gt;
29 #include "vorbis/codec.h"
30 #include "vorbis/vorbisfile.h"
31
32 int main(){
33   OggVorbis_File ov;
34   int i;
35
36 #ifdef _WIN32 /* We need to set stdin to binary mode under Windows */
37   _setmode( _fileno( stdin ), _O_BINARY );
38 #endif
39
40   /* open the file/pipe on stdin */
41   if(ov_open_callbacks(stdin,&amp;ov,NULL,-1,OV_CALLBACKS_NOCLOSE)==-1){
42     printf("Could not open input as an OggVorbis file.\n\n");
43     exit(1);
44   }
45   
46   /* print details about each logical bitstream in the input */
47   if(ov_seekable(&amp;ov)){
48     double length=ov_time_total(&amp;ov,-1);
49     printf("testing seeking to random places in %g seconds....\n",length);
50     for(i=0;i&lt;100;i++){
51       double val=(double)rand()/RAND_MAX*length;
52       ov_time_seek(&amp;ov,val);
53       printf("\r\t%d [%gs]...     ",i,val);
54       fflush(stdout);
55     }
56     
57     printf("\r                                   \nOK.\n\n");
58   }else{
59     printf("Standard input was not seekable.\n");
60   }
61
62   ov_clear(&amp;ov);
63   return 0;
64 }
65
66 </b></pre>
67         </td>
68 </tr>
69 </table>
70
71
72 <br><br>
73 <hr noshade>
74 <table border=0 width=100%>
75 <tr valign=top>
76 <td><p class=tiny>copyright &copy; 2000-2010 Xiph.Org</p></td>
77 <td align=right><p class=tiny><a href="https://xiph.org/vorbis/index.html">Ogg Vorbis</a></p></td>
78 </tr><tr>
79 <td><p class=tiny>Vorbisfile documentation</p></td>
80 <td align=right><p class=tiny>vorbisfile version 1.3.2 - 20101101</p></td>
81 </tr>
82 </table>
83
84 </body>
85
86 </html>