Video Replacement
The PAG SDK is designed specifically for rendering effects. However, the Community Edition does not support audio and video-related content. If you require the option to replace videos with placeholder images, you should consider using the PAG Enterprise Edition.
The PAG Enterprise Edition (the package name has a movie suffix) includes the Movie function, which allows the creation of a PAGMovie using video materials. PAGMovie inherits from PAGImage and can seamlessly replaces the placeholder image of PAGImageLayer. Once replaced, PAGView, PAGPlayer and PAGAudioPlayer will automatically update their internal data and can be presented without any additional steps.
PAGMovie inherits the complete features of PAGImage and the detailed documentation of PAGImage can be found in Android | iOS.
The encapsulation formats supported by PAGMovie are mov, mp4, m4a, 3gp, 3g2, mj2, and the supported encoding formats are h264 and h265 (hevc).
Use Flow
1、Build a PAGMovie Instance
PAGMovie supports building through the native video path and allows for cropping and variable speed and volume settings.
android:
// Method 1: Generate a PAGMovie through the file path, without changing the speed in the default complete interval: duration = file duration us, speed = 1.0f, volume = 1.0f
PAGMovie movie = PAGMovie.MakeFromFile (MOVIE_FILE_PATH);
// Method 2: Generate a PAGMovie through the file path and set the attributes. The parameters here indicate to select the complete interval of the video material. The speed is not changed, and the volume is 0
PAGMovie silentMovie = PAGMovie.MakeFromFile (MOVIE_FILE_PATH, -1, -1, 1, 0);
// Method 3: Generate a PAGMovie through the file path and set the attributes. The parameters here indicate that the video material is selected for 1~3 seconds. The speed is set to 0.5 times, and the volume is 0.5
PAGMovie cutMovie = PAGMovie.MakeFromFile (MOVIE_FILE_PATH, 1_000_000, 2_000_000, 0.5f, 0.5f);
iOS:
// Method 1: Generate a PAGMovie through the file path. Default starttime = 0 us, and duration = file duration us, speed = 1.0f, volume = 1.0f
PAGMovie *movie = [PAGMovie MakeFromFile:moviePath];
// Method 2: Generate a PAGMovie through the file path and set the attributes. The parameters here indicate that the video material is selected for 1~3 seconds. The speed is set to 0.5 times, and the volume is 0.5
// When startTime and duration are both - 1, PAGMovie will automatically adapt to the full duation of the video
movie = [PAGMovie MakeFromFile:moviePath startTime:1*1000*1000 duration:2*1000*1000 speed:0.5f volume:0.5f];
Placeholder Image
2、Replace thePAGMovie is a subclass of PAGImage, and the method of replacing placeholder images is consistent with that of PAGImage.
Note: When the video duration is shorter than the required duration of the image layer, the video will freeze at the last frame.
Code Examples
android:
// Method 1 : Directly replace the image resource
for (int i = 0; i < selectData.size() && i < pagFile.numImages(); i++) {
PAGMovie movie = makePAGMovie(selectData.get(i));
pagFile.replaceImage(i, movie);
}
// Method 2 : Replace with the editable layer
int[] indices = pagFile.getEditableIndices(PAGLayer.LayerTypeImage);
for (int i = 0; i < selectData.size() && i < indices.length; i++) {
PAGMovie movie = makePAGMovie(selectData.get(i));
PAGLayer[] pagLayers = pagFile
.getLayersByEditableIndex(indices[i], PAGLayer.LayerTypeImage);
for (PAGLayer layer : pagLayers) {
((PAGImageLayer) layer).setImage(movie);
}
}
iOS
// Method 1: Directly replaced by PAGFile
for (int i = 0; i < moviePaths.count && i < pagFile.numImages; i++) {
PAGMovie *movie = [PAGMovie MakeFromFile:moviePaths[i]];
[pagFile replaceImage:i data:movie];
}
// Method 2: Replaced by PAGImageLayer
NSArray *indices = [pagFile getEditableIndices:PAGLayerTypeImage];
for (NSUInteger i = 0; i < moviePaths.count && i < indices.count; i++) {
PAGMovie *movie = [PAGMovie MakeFromFile:moviePaths[i]];
NSArray *imageLayers = [pagFile getLayersByEditableIndex:indices[i] layerType:PAGLayerTypeImage];
for (PAGImageLayer *layer in imageLayer) {
[layer setImage:movie];
}
}