Frage

ios 7 with ringtone software does not work. ios 5 and ios 6 are working properly. When I run it with ios 7, duration of the ringtone is the same as the source file is created. Needs to be 40 sec. but it seems to 300-400 seconds.

- (void)Convert{

    AVURLAsset *songAsset = [AVURLAsset URLAssetWithURL:self.audioplayer.url options:nil];

    AVAssetExportSession *exporter = [[AVAssetExportSession alloc]
                                     initWithAsset: songAsset
                                     presetName: AVAssetExportPresetAppleM4A];

    //exporter.outputFileType = @"com.apple.m4a-audio";

    exporter.outputFileType = AVFileTypeAppleM4A;

    CMTime start = CMTimeMakeWithSeconds(self.audioplayer.currentTime, 1);
   CMTime duration = CMTimeMakeWithSeconds(40, 1);
   CMTimeRange range = CMTimeRangeMake(start, duration);
   exporter.timeRange = range;

    NSString *exportFile = [[self kDoc_dosya:self.name] stringByAppendingPathExtension:@"m4r"];


    if ([[NSFileManager defaultManager] fileExistsAtPath:exportFile])
       [[NSFileManager defaultManager] removeItemAtPath:exportFile error:nil];


    NSURL *exportURL = [NSURL fileURLWithPath:exportFile];
   exporter.outputURL = exportURL;

    [exporter exportAsynchronouslyWithCompletionHandler:^{

        int exportStatus = exporter.status;
       switch (exportStatus) {

            case AVAssetExportSessionStatusFailed: {

                NSError *exportError = exporter.error;
               NSLog (@"AVAssetExportSessionStatusFailed: %@", exportError);
               break;
           }
           case AVAssetExportSessionStatusCompleted: {
               NSLog (@"AVAssetExportSessionStatusCompleted--");
               break;
           }
            case AVAssetExportSessionStatusUnknown: { NSLog (@"AVAssetExportSessionStatusUnknown"); break;}
           case AVAssetExportSessionStatusExporting: { NSLog (@"AVAssetExportSessionStatusExporting"); break;}
           case AVAssetExportSessionStatusCancelled: { NSLog (@"AVAssetExportSessionStatusCancelled"); break;}
           case AVAssetExportSessionStatusWaiting: { NSLog (@"AVAssetExportSessionStatusWaiting"); break;}
               default: { NSLog (@"didn't get export status"); break;}
           }

        }];
}
War es hilfreich?

Lösung

Do this to set time range

[songAsset insertTimeRange:CMTimeRangeMake(kCMTimeZero, songAsset.duration)
                     ofTrack:[[songAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0]
                      atTime:kCMTimeZero
                       error:nil];
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top