iPhone開発初心者です。私はiPhoneアプリを開発しています。その中で、私は曲を選ぶために MPMediaController を使用しました。次に、そのファイルを NSData として変換し、サーバーにアップロードします。私のコード 「mp3」ファイルを選択すると問題なく動作しますが、「m4a」ファイルを選択すると問題に直面します。ファイルはデータに変換されますが、AVAudioPlayer で再生して結果データをテストした後、再生されません。解決策を教えてください。または、どこが間違っているのか教えてください。
私のコードは次のとおりです。
-(IBAction)selectMusicButtonPressed:(id)sender
{
     MPMediaPickerController *mediaPicker = [[MPMediaPickerController alloc] initWithMediaTypes:MPMediaTypeMusic];
        mediaPicker.delegate = self;
        mediaPicker.allowsPickingMultipleItems = NO;
    [self presentModalViewController:mediaPicker animated:YES];
}
- (void)mediaPicker: (MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection 
{
   NSURL *url;
   NSMutableData *songData;
    MPMediaItemCollection *collection=mediaItemCollection;//[allAlbumsArray objectAtIndex:0];
    item = [collection representativeItem];
    song_name=[item valueForProperty:MPMediaItemPropertyTitle];
    NSURL *assetURL = [item valueForProperty:MPMediaItemPropertyAssetURL];
    NSString *title=[item valueForProperty:MPMediaItemPropertyTitle];
    if (!assetURL) {
        NSLog(@"%@ has DRM",title);
    }
    else{
        url = [item valueForProperty: MPMediaItemPropertyAssetURL];
       NSString* AssetURL = [NSString stringWithFormat:@"%@",[item valueForProperty:MPMediaItemPropertyAssetURL]];
            url_string=[url absoluteString];
            AVURLAsset *songAsset = [AVURLAsset URLAssetWithURL:url options:nil];
            NSError * error = nil;
            AVAssetReader * reader = [[AVAssetReader alloc] initWithAsset:songAsset error:&error];
            AVAssetTrack * songTrack = [songAsset.tracks objectAtIndex:0];
            AVAssetReaderTrackOutput * output = [[AVAssetReaderTrackOutput alloc] initWithTrack:songTrack outputSettings:nil];
            [reader addOutput:output];
            [output release];
            songData = [[NSMutableData alloc] init];
            [reader startReading];
            while (reader.status == AVAssetReaderStatusReading)
            {
                // AVAssetReaderTrackOutput method
                AVAssetReaderTrackOutput * trackOutput = (AVAssetReaderTrackOutput *)[reader.outputs objectAtIndex:0];
                CMSampleBufferRef sampleBufferRef = [trackOutput copyNextSampleBuffer];
                if (sampleBufferRef)
                {
                    CMBlockBufferRef blockBufferRef = CMSampleBufferGetDataBuffer(sampleBufferRef);
                    size_t length = CMBlockBufferGetDataLength(blockBufferRef);
                    NSLog(@"Size of the song----%zu",length);
                    UInt8 buffer[length];
                    CMBlockBufferCopyDataBytes(blockBufferRef, 0, length, buffer);
                    NSData *data = [[NSData alloc] initWithBytes:buffer length:length];
                    // NSLog(@"song length is %zu",length);
                    // NSLog(@"data is..........%@",data);
                    [songData appendData:data];
                    [data release];
                    CMSampleBufferInvalidate(sampleBufferRef);
                    CFRelease(sampleBufferRef);
                }
            }
            //Testing the result Data
     AVAudioPlayer * player = [[AVAudioPlayer alloc] initWithData:songData] error:NULL]; 
             [player play];
}