@@ -59,7 +59,6 @@ - (void)viewDidLoad {
59
59
[musicLabel sizeToFit ];
60
60
musicLabel.center = CGPointMake (rc.origin .x - musicLabel.bounds .size .width /2 - 5 , self.transitionSwitch .center .y );
61
61
[self .nextButton.superview addSubview: musicLabel];
62
-
63
62
}
64
63
65
64
- (void )viewDidDisappear : (BOOL )animated {
@@ -132,6 +131,7 @@ - (void)nextButtonClick:(UIButton *)sender {
132
131
media.url = [asset movieURL ];
133
132
NSLog (@" Video use url" );
134
133
}
134
+ media.timeRange = CMTimeRangeMake (kCMTimeZero , CMTimeMake (5 * 1000 , 1000 ));
135
135
[mediaItems addObject: media];
136
136
} else if (PHAssetMediaTypeImage == asset.mediaType ) {
137
137
@@ -146,8 +146,7 @@ - (void)nextButtonClick:(UIButton *)sender {
146
146
}
147
147
}];
148
148
149
- PLSComposeMediaItem *media = [[PLSComposeMediaItem alloc ] init ];
150
-
149
+ PLSComposeMediaItem *media = [[PLSComposeMediaItem alloc ] init ];
151
150
media.imageDuration = MAX (3 , arc4random_uniform (8 ));
152
151
if (isGIFImage) {
153
152
media.mediaType = PLSMediaTypeGIF;
@@ -185,40 +184,30 @@ - (void)nextButtonClick:(UIButton *)sender {
185
184
self.imageVideoComposer .musicVolume = 1.0 ;
186
185
self.imageVideoComposer .movieVolume = 1.0 ;
187
186
}
187
+
188
+ self.imageVideoComposer .disableTransition = NO ;
188
189
189
- __weak typeof ( self) weakSelf = self ;
190
+ [ self showWating ] ;
190
191
192
+ __weak typeof (self)weakSelf = self;
193
+
191
194
[self .imageVideoComposer setProcessingBlock: ^(float progress) {
192
195
NSLog (@" process = %f " , progress);
193
196
[weakSelf setProgress: progress];
194
197
}];
195
-
198
+
196
199
[self .imageVideoComposer setCompletionBlock: ^(NSURL * _Nonnull url) {
197
200
NSLog (@" completion" );
198
201
[weakSelf hideWating ];
202
+ weakSelf.progressLabel .text = @" " ;
199
203
200
- // 设置音视频、水印等编辑信息
201
- NSMutableDictionary *outputSettings = [[NSMutableDictionary alloc ] init ];
202
- // 待编辑的原始视频素材
203
- NSMutableDictionary *plsMovieSettings = [[NSMutableDictionary alloc ] init ];
204
- AVAsset *asset = [AVAsset assetWithURL: url];
205
- plsMovieSettings[PLSURLKey] = url;
206
- plsMovieSettings[PLSAssetKey] = asset;
207
- plsMovieSettings[PLSStartTimeKey] = [NSNumber numberWithFloat: 0 .f];
208
- plsMovieSettings[PLSDurationKey] = [NSNumber numberWithFloat: CMTimeGetSeconds (asset.duration)];
209
- plsMovieSettings[PLSVolumeKey] = [NSNumber numberWithFloat: 1 .0f ];
210
- outputSettings[PLSMovieSettingsKey] = plsMovieSettings;
211
-
212
- EditViewController *videoEditViewController = [[EditViewController alloc ] init ];
213
- videoEditViewController.settings = outputSettings;
214
- videoEditViewController.filesURLArray = @[url];
215
- videoEditViewController.modalPresentationStyle = UIModalPresentationFullScreen;
216
- [weakSelf presentViewController: videoEditViewController animated: YES completion: nil ];
217
-
204
+ [weakSelf joinEditViewController: url];
218
205
}];
219
206
220
207
[self .imageVideoComposer setFailureBlock: ^(NSError * _Nonnull error) {
221
208
[weakSelf hideWating ];
209
+ weakSelf.progressLabel .text = @" " ;
210
+
222
211
UIAlertView *alert = [[UIAlertView alloc ] initWithTitle: @" 错误" message: error.localizedDescription delegate: nil cancelButtonTitle: @" 确定" otherButtonTitles: nil ];
223
212
[alert show ];
224
213
}];
@@ -228,25 +217,25 @@ - (void)nextButtonClick:(UIButton *)sender {
228
217
UIAlertController *alert = [UIAlertController alertControllerWithTitle: @" 选择拼接模式" message: @" 同步优先:优先考虑拼接之后音视频的同步性,但是可能造个各个视频的拼接处播放的时候出现音频或者视频卡顿\n 流畅优先:优先考虑拼接之后播放的流畅性,各个视频的拼接处不会出现音视频卡顿现象,但是可能造成音视频不同步\n 视频优先:以每一段视频数据长度来决定每一段音频数据长度\n 音频优先:以每一段音频数据长度来决定每一段视频数据长度" preferredStyle: (UIAlertControllerStyleAlert)];
229
218
230
219
UIAlertAction *syncAction = [UIAlertAction actionWithTitle: @" 同步模式" style: (UIAlertActionStyleDefault) handler: ^(UIAlertAction * _Nonnull action) {
231
- [self showWating ];
220
+ [weakSelf hideWating ];
232
221
self.imageVideoComposer .composerPriorityType = PLSComposerPriorityTypeSync;
233
222
[self .imageVideoComposer startComposing ];
234
223
}];
235
224
236
225
UIAlertAction *smoothAction = [UIAlertAction actionWithTitle: @" 流畅模式" style: (UIAlertActionStyleDefault) handler: ^(UIAlertAction * _Nonnull action) {
237
- [self showWating ];
226
+ [weakSelf hideWating ];
238
227
self.imageVideoComposer .composerPriorityType = PLSComposerPriorityTypeSmooth;
239
228
[self .imageVideoComposer startComposing ];
240
229
}];
241
230
242
231
UIAlertAction *videoAction = [UIAlertAction actionWithTitle: @" 视频优先" style: (UIAlertActionStyleDefault) handler: ^(UIAlertAction * _Nonnull action) {
243
- [self showWating ];
232
+ [weakSelf hideWating ];
244
233
self.imageVideoComposer .composerPriorityType = PLSComposerPriorityTypeVideo;
245
234
[self .imageVideoComposer startComposing ];
246
235
}];
247
236
248
237
UIAlertAction *audioAction = [UIAlertAction actionWithTitle: @" 音频优先" style: (UIAlertActionStyleDefault) handler: ^(UIAlertAction * _Nonnull action) {
249
- [self showWating ];
238
+ [weakSelf hideWating ];
250
239
self.imageVideoComposer .composerPriorityType = PLSComposerPriorityTypeAudio;
251
240
[self .imageVideoComposer startComposing ];
252
241
}];
@@ -259,11 +248,31 @@ - (void)nextButtonClick:(UIButton *)sender {
259
248
[self presentViewController: alert animated: YES completion: nil ];
260
249
261
250
} else {
262
- [self showWating ];
263
251
[self .imageVideoComposer startComposing ];
264
252
}
265
253
}
266
254
255
+ // 进入编辑页面
256
+ - (void )joinEditViewController : (NSURL *)url {
257
+ // 设置音视频、水印等编辑信息
258
+ NSMutableDictionary *outputSettings = [[NSMutableDictionary alloc ] init ];
259
+ // 待编辑的原始视频素材
260
+ NSMutableDictionary *plsMovieSettings = [[NSMutableDictionary alloc ] init ];
261
+ AVAsset *asset = [AVAsset assetWithURL: url];
262
+ plsMovieSettings[PLSURLKey] = url;
263
+ plsMovieSettings[PLSAssetKey] = asset;
264
+ plsMovieSettings[PLSStartTimeKey] = [NSNumber numberWithFloat: 0 .f];
265
+ plsMovieSettings[PLSDurationKey] = [NSNumber numberWithFloat: CMTimeGetSeconds (asset.duration)];
266
+ plsMovieSettings[PLSVolumeKey] = [NSNumber numberWithFloat: 1 .0f ];
267
+ outputSettings[PLSMovieSettingsKey] = plsMovieSettings;
268
+
269
+ EditViewController *videoEditViewController = [[EditViewController alloc ] init ];
270
+ videoEditViewController.settings = outputSettings;
271
+ videoEditViewController.filesURLArray = @[url];
272
+ videoEditViewController.modalPresentationStyle = UIModalPresentationFullScreen;
273
+ [self presentViewController: videoEditViewController animated: YES completion: nil ];
274
+ }
275
+
267
276
- (void )fetchAssetsWithMediaType : (PHAssetMediaType)mediaType {
268
277
__weak __typeof (self) weak = self;
269
278
dispatch_async (dispatch_get_global_queue (0 , 0 ), ^{
0 commit comments