seeking_example.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /********************************************************************
  2. * *
  3. * THIS FILE IS PART OF THE Ogg Vorbis SOFTWARE CODEC SOURCE CODE. *
  4. * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
  5. * THE GNU PUBLIC LICENSE 2, WHICH IS INCLUDED WITH THIS SOURCE. *
  6. * PLEASE READ THESE TERMS DISTRIBUTING. *
  7. * *
  8. * THE OggSQUISH 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.1.2.1 2000/04/06 15:59:36 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)==-1){
  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. ov_time_seek(&ov,drand48()*length);
  35. printf("\r\t%d... ",i);
  36. fflush(stdout);
  37. }
  38. printf("\r \nOK.\n\n");
  39. }else{
  40. printf("Standard input was not seekable.\n");
  41. }
  42. ov_clear(&ov);
  43. return 0;
  44. }