Note that there are some explanatory texts on larger screens.

plurals
  1. POAVAudioPlayer refuses to play modified wav file
    text
    copied!<p>The first time i call this method <code>file1</code> will be nil and <code>file2</code> will be returned. When this hapens the file will play normally (so the calling of this method should be fine). But when i call it for the second time it will return an <code>NSURL</code> which the AVAudioPlayer does not play. My guess is I have missed something in the header. In the debugging mode i have seen that the <code>totalLength</code> is exactly as long as the data's length. </p> <pre><code>+(NSURL *)mergeFile1:(NSURL *)file1 withFile2:(NSURL *)file2 { if(file1 == nil) { return [file2 copy]; } NSData * wav1Data = [NSData dataWithContentsOfURL:file1]; NSData * wav2Data = [NSData dataWithContentsOfURL:file2]; int wav1DataSize = [wav1Data length] - 46; int wav2DataSize = [wav2Data length] - 46; if (wav1DataSize &lt;= 0 || wav2DataSize &lt;= 0) { return nil; } NSMutableData * soundFileData = [NSMutableData dataWithData:[wav1Data subdataWithRange:NSMakeRange(0, 46)]]; [soundFileData appendData:[wav1Data subdataWithRange:NSMakeRange(46, wav1DataSize)]]; [soundFileData appendData:[wav2Data subdataWithRange:NSMakeRange(46, wav2DataSize)]]; unsigned int totalLength = [soundFileData length]; NSLog(@"Calculated: %d - Real: %d", totalLength, [soundFileData length]); [soundFileData replaceBytesInRange:NSMakeRange(4, 4) withBytes:&amp;(UInt32){NSSwapHostIntToLittle(totalLength-8)}]; [soundFileData replaceBytesInRange:NSMakeRange(42, 4) withBytes:&amp;(UInt32){NSSwapHostIntToLittle(totalLength)}]; [soundFileData writeToURL:file1 atomically:YES]; return [file1 copy]; } </code></pre> <p>If anyone sees something that can be of help it would be much appreciated! Any questions will be answered asap.</p> <p><strong>EDIT</strong></p> <p>I know there are 2 sorts of wav headers: 44 bytes or 46 bytes. I have tried both.</p> <p><strong>EDIT</strong></p> <p>I have looked at the <a href="http://developer.apple.com/library/ios/#documentation/MusicAudio/Reference/AudioFileConvertRef/Reference/reference.html" rel="nofollow">Audio File Services Reference</a> which contains a lot of nice stuff i might want to use, but i can't figure out how to use all this. I'm not really known with c. Hope anyone could help me out with this.</p> <p><strong>EDIT</strong></p> <p>An example of a merged wav file is found here: <a href="http://www.2shared.com/audio/rtfbVJO7/7--443522512.html" rel="nofollow">7--443522512</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload