Add URL support to seeking_example.
authorTimothy B. Terriberry <tterribe@xiph.org>
Sat, 22 Sep 2012 17:16:14 +0000 (10:16 -0700)
committerTimothy B. Terriberry <tterribe@xiph.org>
Sat, 22 Sep 2012 17:16:14 +0000 (10:16 -0700)
Also fixes some indenting in opusfile_example.

examples/opusfile_example.c
examples/seeking_example.c

index 6232324..61e5a69 100644 (file)
@@ -43,14 +43,14 @@ int main(int _argc,const char **_argv){
     of=op_open_url(_argv[1],OP_SSL_SKIP_CERTIFICATE_CHECK,&ret);
 #if 0
     if(of==NULL){
-        OpusFileCallbacks  cb={NULL,NULL,NULL,NULL};
-        void              *fp;
-        /*For debugging: force a file to not be seekable.*/
-        fp=op_fopen(&cb,_argv[1],"rb");
-        cb.seek=NULL;
-        cb.tell=NULL;
-        of=op_open_callbacks(fp,&cb,NULL,0,NULL);
-      }
+      OpusFileCallbacks  cb={NULL,NULL,NULL,NULL};
+      void              *fp;
+      /*For debugging: force a file to not be seekable.*/
+      fp=op_fopen(&cb,_argv[1],"rb");
+      cb.seek=NULL;
+      cb.tell=NULL;
+      of=op_open_callbacks(fp,&cb,NULL,0,NULL);
+    }
 #else
     if(of==NULL)of=op_open_file(_argv[1],&ret);
 #endif
index 97b92d8..a2eac93 100644 (file)
@@ -248,7 +248,12 @@ int main(int _argc,const char **_argv){
   }
   memset(&cb,0,sizeof(cb));
   if(strcmp(_argv[1],"-")==0)fp=op_fdopen(&cb,fileno(stdin),"rb");
-  else fp=op_fopen(&cb,_argv[1],"rb");
+  else{
+    /*Try to treat the argument as a URL.*/
+    fp=op_url_stream_create(&cb,_argv[1],OP_SSL_SKIP_CERTIFICATE_CHECK);
+    /*Fall back assuming it's a regular file name.*/
+    if(fp==NULL)fp=op_fopen(&cb,_argv[1],"rb");
+  }
   if(cb.seek!=NULL){
     real_seek=cb.seek;
     cb.seek=seek_stat_counter;