Skip to content

Commit

Permalink
1.Add a slider to the demo - "control progress manually";
Browse files Browse the repository at this point in the history
2.Modify the linux CMakeLists.txt.
  • Loading branch information
fusionxu authored and domchen committed Jan 24, 2022
1 parent 1214024 commit 96f9c4d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
12 changes: 12 additions & 0 deletions ios/PAGViewer/Full/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -556,9 +556,21 @@
<view key="view" contentMode="scaleToFill" id="uj1-cN-Dw3">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<slider opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" value="0.5" minValue="0.0" maxValue="1" translatesAutoresizingMaskIntoConstraints="NO" id="90I-D8-65R">
<rect key="frame" x="18" y="790" width="378" height="30"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
<connections>
<action selector="sliderValueChanged:" destination="8H2-fb-z0E" eventType="valueChanged" id="6IN-My-6Ls"/>
</connections>
</slider>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</view>
<navigationItem key="navigationItem" id="41h-G7-5WM"/>
<connections>
<outlet property="progressSlider" destination="90I-D8-65R" id="uGK-Ju-fah"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="HWY-gf-anI" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
Expand Down
28 changes: 21 additions & 7 deletions ios/PAGViewer/Full/ViewController/PixelBufferDemoViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ @interface PixelBufferDemoViewController ()

@property (nonatomic, strong) PAGPlayer* player;

@property (nonatomic, strong) UIImageView* imageView;

@property (weak, nonatomic) IBOutlet UISlider *progressSlider;

@end


Expand All @@ -38,17 +42,27 @@ - (void)viewDidLoad {
//初始化PAG组件
[self initPAG];
//替换数据demo方法
[self replaceImageAndText];
// [self replaceImageAndText];
//进度控制和渲染,result为渲染结果
CVPixelBufferRef result = [self presentOnce];
CVPixelBufferRef result = [self presentOnceWithProgress:0.5f];
UIImage* image = [self.class imageFromCVPixelBufferRef:result];
UIImageView* imageView = [[UIImageView alloc] initWithImage:image];
[self.view addSubview:imageView];
self.imageView = [[UIImageView alloc] initWithImage:image];
[self.view addSubview:self.imageView];
[self.view bringSubviewToFront:self.progressSlider];
}

- (IBAction)sliderValueChanged:(id)sender {
float value = ((UISlider *)sender).value;
__weak typeof(self) weakself = self;
dispatch_async(dispatch_get_main_queue(), ^{
CVPixelBufferRef result = [weakself presentOnceWithProgress:value];
weakself.imageView.image = [weakself.class imageFromCVPixelBufferRef:result];
});
}

- (void)initPAG {
//文件加载
NSString* path = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"pag"];
NSString* path = [[NSBundle mainBundle] pathForResource:@"replacement" ofType:@"pag"];
self.file = [PAGFile Load:path];
//player是libpag3.0中的控制器,用于播放进度控制,与surface为一一对应的关系。
//render之中的功能转移到了PAGPlayer和PAGFile中。如果需要绘制多个File的内容,可以使用PAGComposition组装PAGFile。具体请看{@link CombinePAGViewController}
Expand All @@ -60,8 +74,8 @@ - (void)initPAG {
[self.player setComposition:self.file];
}

- (CVPixelBufferRef)presentOnce {
[self.player setProgress:0.5];
- (CVPixelBufferRef)presentOnceWithProgress:(float)value {
[self.player setProgress:value];
[self.player flush];
return [self.surface getCVPixelBuffer];
}
Expand Down
2 changes: 1 addition & 1 deletion linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ if (APPLE)
find_library(VIDEOTOOLBOX VideoToolbox)
list(APPEND libs ${VIDEOTOOLBOX})

list(APPEND libs ${CMAKE_CURRENT_SOURCE_DIR}/vendor/pag/mac/x64/libpag.dylib)
list(APPEND libs ${CMAKE_CURRENT_SOURCE_DIR}/vendor/pag/mac/x64/libpag.a)
list(APPEND libs ${CMAKE_CURRENT_SOURCE_DIR}/vendor/swiftshader/mac/x64/libEGL.dylib)
list(APPEND libs ${CMAKE_CURRENT_SOURCE_DIR}/vendor/swiftshader/mac/x64/libGLESv2.dylib)

Expand Down

0 comments on commit 96f9c4d

Please sign in to comment.