Skip to content

Commit

Permalink
Merge pull request #11 from HeraShowFeng/master
Browse files Browse the repository at this point in the history
release v1.3.0
  • Loading branch information
lawder authored Aug 24, 2017
2 parents ba75953 + 5a7b807 commit e819e35
Show file tree
Hide file tree
Showing 48 changed files with 1,293 additions and 512 deletions.
53 changes: 53 additions & 0 deletions APIDiffs/api-diffs-1.3.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# PLShortVideoKit 1.2.1 to 1.3.0 API Differences

## General Headers

```
PLShortVideoRecorder.h
```

- *Added* @property (assign, nonatomic) BOOL adaptationRecording;
- *Added* @property (copy, nonatomic) void(^ _Nullable deviceOrientationBlock)(PLSPreviewOrientation deviceOrientation);


- *Added* class `PLSGifComposer`


```
PLSEditorPlayer.h
```

- *Added* + (PLSEditPlayer *_Nullable)audioPlayer;


```
PLSFilter.h
```

- *Added* @property (strong, nonatomic) NSString *colorImagePath;
- *Added* - (instancetype)init;


```
PLSTypeDefines.h
```

- *Added* typedef NS_ENUM(NSInteger, PLSPreviewOrientation) {
PLSPreviewOrientationPortrait = 1,
PLSPreviewOrientationPortraitUpsideDown = 2,
PLSPreviewOrientationLandscapeRight = 3,
PLSPreviewOrientationLandscapeLeft = 4,
};













84 changes: 49 additions & 35 deletions Example/PLShortVideoKitDemo.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion Example/PLShortVideoKitDemo/ClipMovieViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ - (void)viewDidLoad {
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];

[self.shortVideoEditor.player seekToTime:CMTimeMake(self.startTime, 1) toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero];
[self.shortVideoEditor.player seekToTime:CMTimeMake(self.startTime * 1e9, 1e9) toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero];
[self.shortVideoEditor.player play];
[self startPlaybackTimeChecker];
}
Expand Down Expand Up @@ -239,6 +239,8 @@ - (void)didReceiveMemoryWarning {

#pragma mark -- dealloc
- (void)dealloc {
NSLog(@"dealloc: %@", [[self class] description]);

if (self.playbackTimeCheckerTimer) {
[self.playbackTimeCheckerTimer invalidate];
self.playbackTimeCheckerTimer = nil;
Expand Down
111 changes: 48 additions & 63 deletions Example/PLShortVideoKitDemo/EditViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
#import "PLSClipAudioView.h"
#import "PLSFilterGroup.h"
#import <AssetsLibrary/AssetsLibrary.h>
#import "Stalker.h"
#import "GifFormatViewController.h"


#define PLS_RGBCOLOR(r,g,b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1]

Expand Down Expand Up @@ -62,10 +63,6 @@ @interface EditViewController ()
@property (strong, nonatomic) UICollectionView *musicCollectionView;
@property (strong, nonatomic) NSMutableArray *musicsArray;

// 视频
@property (strong, nonatomic) NSTimer *moviePlayTimeCheckerTimer;
@property (assign, nonatomic) CGFloat movieCurrentTime;

@end

@implementation EditViewController
Expand Down Expand Up @@ -136,6 +133,7 @@ - (void)viewDidLoad {
CMTime start = CMTimeMake([self.movieSettings[PLSStartTimeKey] floatValue] * 1e9, 1e9);
CMTime duration = CMTimeMake([self.movieSettings[PLSDurationKey] floatValue] * 1e9, 1e9);
self.shortVideoEditor.player.timeRange = CMTimeRangeMake(start, duration);

self.shortVideoEditor.audioPlayer.loopEnabled = YES;

// 滤镜
Expand All @@ -145,36 +143,15 @@ - (void)viewDidLoad {
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];

// player
[self.shortVideoEditor.player.stalker when:UIApplicationWillResignActiveNotification then:^(NSNotification *notification) {
NSLog(@"[shortVideoEditor.player UIApplicationWillResignActiveNotification]");
[self.shortVideoEditor.player pause];
}];
[self.shortVideoEditor.player.stalker when:UIApplicationDidBecomeActiveNotification then:^(NSNotification *notification) {
NSLog(@"[shortVideoEditor.player, UIApplicationDidBecomeActiveNotification]");
[self.shortVideoEditor.player play];
}];
// audioPlayer
[self.shortVideoEditor.audioPlayer.stalker when:UIApplicationWillResignActiveNotification then:^(NSNotification *notification) {
NSLog(@"[shortVideoEditor.audioPlayer UIApplicationWillResignActiveNotification]");
[self.shortVideoEditor.audioPlayer pause];
}];
[self.shortVideoEditor.audioPlayer.stalker when:UIApplicationDidBecomeActiveNotification then:^(NSNotification *notification) {
NSLog(@"[shortVideoEditor.audioPlayer, UIApplicationDidBecomeActiveNotification]");
[self.shortVideoEditor.audioPlayer play];
}];
[self startPlaybackTimeChecker];
[self.shortVideoEditor.player seekToTime:CMTimeMake([self.movieSettings[PLSStartTimeKey] floatValue] * 1e9, 1e9) toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero];
[self observerUIApplicationStatusForShortVideoEditor];
[self.shortVideoEditor.player play];
[self.shortVideoEditor.audioPlayer play];
}

- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];

[self.shortVideoEditor.player.stalker unobserveAll];
[self.shortVideoEditor.audioPlayer.stalker unobserveAll];
[self stopPlaybackTimeChecker];
[self removeObserverUIApplicationStatusForShortVideoEditor];
[self.shortVideoEditor.player pause];
[self.shortVideoEditor.audioPlayer pause];
}
Expand Down Expand Up @@ -237,6 +214,15 @@ - (void)setupEditToolboxView {
filterButton.titleLabel.font = [UIFont systemFontOfSize:14];
[self.editToolboxView addSubview:filterButton];

// 制作Gif图
UIButton *formGifButton = [UIButton buttonWithType:UIButtonTypeCustom];
formGifButton.frame = CGRectMake(CGRectGetWidth(self.view.frame) - 180, 0, 35, 35);
[formGifButton setImage:[UIImage imageNamed:@"icon_gif"] forState:UIControlStateNormal];
formGifButton.titleLabel.font = [UIFont systemFontOfSize:14];
[self.editToolboxView addSubview:formGifButton];
[formGifButton addTarget:self action:@selector(formatGifButtonEvent:) forControlEvents:UIControlEventTouchUpInside];


// 裁剪背景音乐
UIButton *clipMusicButton = [UIButton buttonWithType:UIButtonTypeCustom];
clipMusicButton.frame = CGRectMake(CGRectGetWidth(self.view.frame) - 140, 0, 35, 35);
Expand Down Expand Up @@ -280,7 +266,7 @@ - (void)setupEditToolboxView {
[self.musicCollectionView reloadData];

// 展示拼接视频的进度
self.progressLabel = [[UILabel alloc] initWithFrame:CGRectMake(160, 0, 110, 45)];
self.progressLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetWidth(self.view.frame) - 270, 0, 90, 45)];
self.progressLabel.textAlignment = NSTextAlignmentLeft;
self.progressLabel.textColor = [UIColor whiteColor];
[self.editToolboxView addSubview:self.progressLabel];
Expand Down Expand Up @@ -344,7 +330,7 @@ - (NSMutableArray *)musicsArray {


NSDictionary *dic = @{
@"audioName" : @"None",
@"audioName" : @"",
@"audioUrl" : @"NULL",
};
[array addObject:dic];
Expand Down Expand Up @@ -540,7 +526,6 @@ - (void)audioVolumeView:(PLSAudioVolumeView *)volumeView movieVolumeChangedTo:(C
- (void)restart {
// 影片
[self.shortVideoEditor.player setItemByAsset:self.movieSettings[PLSAssetKey]];
[self.shortVideoEditor.player seekToTime:CMTimeMake([self.movieSettings[PLSStartTimeKey] floatValue] * 1e9, 1e9) toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero];
self.shortVideoEditor.player.volume = [self.movieSettings[PLSVolumeKey] floatValue];
[self.shortVideoEditor.player play];

Expand Down Expand Up @@ -574,6 +559,11 @@ - (void)assetExportSession:(PLSFile *)file didOutputProgress:(CGFloat)progress {
}

#pragma mark -- UIButton 按钮响应事件
#pragma mark -- 制作Gif图
- (void)formatGifButtonEvent:(id)sender {
[self joinGifFormatViewController];
}

#pragma mark -- 裁剪背景音乐
- (void)clipMusicButtonEvent:(id)sender {
CMTimeRange currentMusicTimeRange = CMTimeRangeMake(CMTimeMake([self.audioSettings[PLSStartTimeKey] floatValue] * 1e9, 1e9), CMTimeMake([self.audioSettings[PLSDurationKey] floatValue] * 1e9, 1e9));
Expand Down Expand Up @@ -650,6 +640,15 @@ - (void)nextButtonClick {
weakSelf.progressLabel.text = [NSString stringWithFormat:@"%d%%", (int)(progress * 100)];
}];
}

#pragma mark -- 进入 Gif 制作页面
- (void)joinGifFormatViewController {
AVAsset *asset = self.movieSettings[PLSAssetKey];

GifFormatViewController *gifFormatViewController = [[GifFormatViewController alloc] init];
gifFormatViewController.asset = asset;
[self presentViewController:gifFormatViewController animated:YES completion:nil];
}

#pragma mark -- 完成视频合成跳转到下一页面
- (void)joinNextViewController:(NSURL *)url object:(id)obj {
Expand All @@ -660,42 +659,28 @@ - (void)joinNextViewController:(NSURL *)url object:(id)obj {
[obj presentViewController:playViewController animated:YES completion:nil];
}

#pragma mark -- PlaybackTimeCheckerTimer
- (void)startPlaybackTimeChecker {
[self stopPlaybackTimeChecker];

self.moviePlayTimeCheckerTimer = [NSTimer scheduledTimerWithTimeInterval:0.1f target:self selector:@selector(onPlaybackTimeCheckerTimer) userInfo:nil repeats:YES];
#pragma mark -- 程序的状态监听
- (void)observerUIApplicationStatusForShortVideoEditor {
// player, audioPlayer
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(shortVideoEditorWillResignActiveEvent:) name:UIApplicationWillResignActiveNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(shortVideoEditorDidBecomeActiveEvent:) name:UIApplicationDidBecomeActiveNotification object:nil];
}

- (void)stopPlaybackTimeChecker {
if (self.moviePlayTimeCheckerTimer) {
[self.moviePlayTimeCheckerTimer invalidate];
self.moviePlayTimeCheckerTimer = nil;
}
- (void)removeObserverUIApplicationStatusForShortVideoEditor {
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillResignActiveNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil];
}

- (void)onPlaybackTimeCheckerTimer {
CMTime curTime = [self.shortVideoEditor.player currentTime];
Float64 seconds = CMTimeGetSeconds(curTime);
if (seconds < 0){
seconds = 0; // this happens! dont know why.
}
self.movieCurrentTime = seconds;

CGFloat startTime = [self.movieSettings[PLSStartTimeKey] floatValue];
CGFloat endTime = startTime + [self.movieSettings[PLSDurationKey] floatValue];

if (self.movieCurrentTime >= endTime) {
self.movieCurrentTime = startTime;
[self seekVideoToPos:startTime];
}
- (void)shortVideoEditorWillResignActiveEvent:(id)sender {
NSLog(@"[self.shortVideoEditor UIApplicationWillResignActiveNotification]");
[self.shortVideoEditor.player pause];
[self.shortVideoEditor.audioPlayer pause];
}

- (void)seekVideoToPos:(CGFloat)pos {
self.movieCurrentTime = pos;
CMTime time = CMTimeMakeWithSeconds(self.movieCurrentTime, self.shortVideoEditor.player.currentTime.timescale);
NSLog(@"seekVideoToPos time:%.2f", CMTimeGetSeconds(time));
[self.shortVideoEditor.player seekToTime:time toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero];
- (void)shortVideoEditorDidBecomeActiveEvent:(id)sender {
NSLog(@"[self.shortVideoEditor UIApplicationDidBecomeActiveNotification]");
[self.shortVideoEditor.player play];
[self.shortVideoEditor.audioPlayer play];
}

#pragma mark -- 隐藏状态栏
Expand All @@ -705,6 +690,8 @@ - (BOOL)prefersStatusBarHidden {

#pragma mark -- dealloc
- (void)dealloc {
NSLog(@"dealloc: %@", [[self class] description]);

self.shortVideoEditor.player.delegate = nil;
self.shortVideoEditor.player = nil;

Expand All @@ -724,8 +711,6 @@ - (void)dealloc {
[self.activityIndicatorView stopAnimating];
self.activityIndicatorView = nil;
}

[self stopPlaybackTimeChecker];
}

@end
Expand Down
17 changes: 17 additions & 0 deletions Example/PLShortVideoKitDemo/GifFormatViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// GifFormatViewController.h
// PLShortVideoKitDemo
//
// Created by 冯文秀 on 2017/7/31.
// Copyright © 2017年 Pili Engineering, Qiniu Inc. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>

@interface GifFormatViewController : UIViewController

@property (strong, nonatomic) AVAsset *asset;

@end
Loading

0 comments on commit e819e35

Please sign in to comment.