0

thanks for your help,my problem is : i need to convert a aac audio file to byte data then i can transmit this data to the server by using tcp.but i can not convert aac to byte. i use:

NSString *docDir = NSTemporaryDirectory();
NSString* _tempRecorderPath;
_tempRecorderPath = [docDir stringByAppendingPathComponent:@"ringtones_tmp.aac"];
NSData *testringdata=[NSData dataWithContentsOfFile:_tempRecorderPath];
Byte *nbyteData=(Byte*)[ringData bytes];

but the result is there is only '\xff' in nbyteData! i do not know why ? And how to fix it!!

Justin Paulson
  • 4,388
  • 1
  • 23
  • 28
darkNight
  • 1
  • 1

2 Answers2

0

try this:-

NSData *data = [NSData dataWithContentsOfFile:filePath];
NSUInteger len = [data length];
Byte *byteData = (Byte*)malloc(len);
memcpy(byteData, [data bytes], len);

This code will dynamically allocate the array to the correct size (you must free(byteData) when you're done) and copy the bytes into it.

Dheeraj Kumar
  • 441
  • 3
  • 16
0

Have a look at this link . This link explains exactly what you want

NSData *data = [NSData dataWithContentsOfFile:filePath];
NSUInteger len = [data length];
Byte *byteData = (Byte*)malloc(len);
memcpy(byteData, [data bytes], len);
Community
  • 1
  • 1
iOSAppDev
  • 2,755
  • 4
  • 39
  • 77