@@ -473,23 +473,24 @@ - (void)fetchFullSizeVideo:(PHAsset *)asset handler:(NSObject <PMResultHandler>
473
473
attributes: @{}
474
474
error: nil ];
475
475
476
- [path appendFormat: @" %@ /%@ " , @" .video" , filename];
476
+ [path appendFormat: @" %@ /%d _%@ " , @" .video" , (int )asset.modificationDate.timeIntervalSince1970 ,filename];
477
+
477
478
PHVideoRequestOptions *options = [PHVideoRequestOptions new ];
479
+ options.version = PHVideoRequestOptionsVersionCurrent;
478
480
if ([manager fileExistsAtPath: path]) {
479
481
[[PMLogUtils sharedInstance ]
480
482
info: [NSString stringWithFormat: @" read cache from %@ " , path]];
481
483
[handler reply: path];
482
484
return ;
483
485
}
484
-
485
-
486
+
486
487
[self notifyProgress: progressHandler progress: 0 state: PMProgressStatePrepare];
487
488
[options setProgressHandler: ^(double progress, NSError *error, BOOL *stop,
488
- NSDictionary *info) {
489
+ NSDictionary *info) {
489
490
if (progress == 1.0 ) {
490
- [self fetchFullSizeVideo: asset handler: handler progressHandler: nil ];
491
+ [self notifyProgress: progressHandler progress: progress state: PMProgressStateLoading ];
491
492
}
492
-
493
+
493
494
if (error) {
494
495
[self notifyProgress: progressHandler progress: progress state: PMProgressStateFailed];
495
496
[progressHandler deinit ];
@@ -501,35 +502,36 @@ - (void)fetchFullSizeVideo:(PHAsset *)asset handler:(NSObject <PMResultHandler>
501
502
}];
502
503
503
504
[options setNetworkAccessAllowed: YES ];
504
-
505
505
[[PHImageManager defaultManager ]
506
- requestAVAssetForVideo: asset
507
- options: options
508
- resultHandler: ^(AVAsset *_Nullable asset,
509
- AVAudioMix *_Nullable audioMix,
510
- NSDictionary *_Nullable info) {
511
- BOOL downloadFinish = [PMManager isDownloadFinish: info];
512
-
513
- if (!downloadFinish) {
514
- return ;
515
- }
516
-
517
- NSString *preset = AVAssetExportPresetHighestQuality;
518
- AVAssetExportSession *exportSession =
519
- [AVAssetExportSession exportSessionWithAsset: asset
520
- presetName: preset];
521
- if (exportSession) {
522
- exportSession.outputFileType = AVFileTypeMPEG4;
523
- exportSession.outputURL = [NSURL fileURLWithPath: path];
524
- [exportSession exportAsynchronouslyWithCompletionHandler: ^{
525
- [handler reply: path];
526
- }];
527
-
528
- [self notifySuccess: progressHandler];
529
- } else {
530
- [handler reply: nil ];
531
- }
532
- }];
506
+ requestExportSessionForVideo: asset options: options exportPreset: AVAssetExportPresetHighestQuality resultHandler: ^(AVAssetExportSession *_Nullable exportSession, NSDictionary *_Nullable info) {
507
+ BOOL downloadFinish = [PMManager isDownloadFinish: info];
508
+
509
+ if (!downloadFinish) {
510
+ NSLog (@" Asset download fail: %@ " );
511
+ [handler reply: nil ];
512
+ return ;
513
+ }
514
+
515
+ if (exportSession) {
516
+ exportSession.shouldOptimizeForNetworkUse = YES ;
517
+ exportSession.outputFileType = AVFileTypeMPEG4;
518
+ exportSession.outputURL = [NSURL fileURLWithPath: path];
519
+ [exportSession exportAsynchronouslyWithCompletionHandler: ^{
520
+ if ([exportSession status ] == AVAssetExportSessionStatusCompleted) {
521
+ [handler reply: path];
522
+ } else if ([exportSession status ] == AVAssetExportSessionStatusFailed) {
523
+ NSLog (@" Export session failed: %@ " , exportSession.error );
524
+ [handler reply: nil ];
525
+ } else if ([exportSession status ] == AVAssetExportSessionStatusCancelled) {
526
+ NSLog (@" Export session cancelled: %@ " , exportSession.error );
527
+ [handler reply: nil ];
528
+ }
529
+ }];
530
+ [self notifySuccess: progressHandler];
531
+ } else {
532
+ [handler reply: nil ];
533
+ }
534
+ }];
533
535
}
534
536
535
537
- (NSString *)makeAssetOutputPath : (PHAsset *)asset isOrigin : (Boolean )isOrigin {
0 commit comments