seeking_example.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /********************************************************************
  2. * *
  3. * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
  4. * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
  5. * THE GNU LESSER/LIBRARY PUBLIC LICENSE, WHICH IS INCLUDED WITH *
  6. * THIS SOURCE. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
  7. * *
  8. * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2000 *
  9. * by Monty <monty@xiph.org> and the XIPHOPHORUS Company *
  10. * http://www.xiph.org/ *
  11. * *
  12. ********************************************************************
  13. function: illustrate seeking, and test it too
  14. last mod: $Id: seeking_example.c,v 1.4.2.2 2000/11/04 06:21:39 xiphmont Exp $
  15. ********************************************************************/
  16. #include <stdlib.h>
  17. #include <stdio.h>
  18. #include "vorbis/codec.h"
  19. #include "vorbis/vorbisfile.h"
  20. #include "../lib/misc.h"
  21. int main(){
  22. OggVorbis_File ov;
  23. int i;
  24. /* open the file/pipe on stdin */
  25. if(ov_open(stdin,&ov,NULL,-1)<0){
  26. printf("Could not open input as an OggVorbis file.\n\n");
  27. exit(1);
  28. }
  29. /* print details about each logical bitstream in the input */
  30. if(ov_seekable(&ov)){
  31. double length=ov_time_total(&ov,-1);
  32. printf("testing seeking to random places in %g seconds....\n",length);
  33. for(i=0;i<100;i++){
  34. double val=(double)rand()/RAND_MAX*length;
  35. ov_time_seek(&ov,val);
  36. printf("\r\t%d [%gs]... ",i,val);
  37. fflush(stdout);
  38. }
  39. printf("\r \nOK.\n\n");
  40. }else{
  41. printf("Standard input was not seekable.\n");
  42. }
  43. ov_clear(&ov);
  44. return 0;
  45. }