title: How to use ogg.framwork in xcode to play audio from url or data
body: <p>From couple of days I was searching of how to play ogg on iPhone. But not successful. I found <a href="https://stackoverflow.com/questions/10804046/playing-an-ogg-stream-in-ios">this post</a> which points towards <a href="http://iosdeveloperzone.com/2012/08/07/precompiled-ogg-vorbis-libraries-for-ios/" rel="nofollow noreferrer">precompiled-ogg-vorbis-libraries-for-ios</a>, but I don't know how to use this framework or libraries. I am new in coding. I also found <a href="https://stackoverflow.com/questions/4745618/ogg-vorbis-in-iphone-sdk?lq=1">this post</a>
   but it plays ogg audio from bundle. I want to play from a given url, like wikipedia audios. any help will be great. Thanks </p>
  
  <p>UPDATE:</p>
  
  <p>I found another library or file which can be use in iOS but, still I don't know how to use in Xcode. <a href="http://www.nothings.org/stb_vorbis/" rel="nofollow noreferrer">Ogg Vorbis I audio decoder by  Sean Barrett</a>. Any idea how to use this. </p>
  
  <p>UPDATE 2:</p>
  
  <p>Just tried to use it something like this, but output file have no sound. Any idea where I am going wrong. </p>
  
  <pre><code>NSString *file = @"http://upload.wikimedia.org/wikipedia/commons/b/b2/En-us-Pakistan.ogg";
      NSURL *fileURL = [NSURL URLWithString:file];
  
      NSData * data = [NSData dataWithContentsOfURL:fileURL];
      unsigned char* array = (unsigned char*) [data bytes];
      int len = [data length];
  
      if (data != nil) {
          NSLog(@"\nis not nil");
          //NSString *readdata = [[NSString alloc] initWithContentsOfURL:(NSData *)data ];
          stb_vorbis* Stream = stb_vorbis_open_memory(array, len, NULL, NULL);
  
          if (Stream)
          {
              stb_vorbis_close(Stream);
              //return true;
          }
          else
          {
              //return false;
          }
      }
  
      Byte *byteData = (Byte*)malloc(len);
  
      memcpy(byteData, [data bytes], len);
      NSData *ddata = [NSData dataWithBytes:byteData length:len];
  
      if (ddata == nil) {
          NSLog(@"data nil");
      }
      else{
  
  
      NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
      NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder
      NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"wikiaudio"];
      NSError *error;
  
      if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath])
          [[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:&amp;error]; //Create folder if it doesn't already exist
  
      NSString * filename = [@"hello" stringByAppendingString:@".mp3"];
      NSString  *filePath = [NSString stringWithFormat:@"%@/%@", dataPath,filename];
      [ddata writeToFile:filePath atomically:YES];
          NSLog(@"filepath %@", filePath);
      }
  </code></pre>