PAG官网 | PAG动效

PAG官网 | PAG动效

  • 首页
  • 产品
  • 功能
  • 文档
  • 案例
  • CN
  • GitHub
  • 论坛交流
  • 免费下载
  • Languages iconEN
    • CN

›移动端进阶

了解 PAG

  • Introduction
  • FAQs

快速开始

  • Install PAGViewer
  • Install PAGExporter
  • Export PAG Files
  • SDK Integration

导出插件

  • Use Configuration Panel
  • Use Exporting Panel
  • Export BMP Compositions
  • Config Fill Modes
  • Config Time Stretch Modes
  • Exporting Shortcut Keys
  • Error Code
  • Auto Detection Rules
  • Text Editing Rules
  • Add Text Background
  • Export Audio
  • Manually Install PAGExporter

预览工具

  • Preview Replacements
  • View File Structure
  • Preview Shortcut Keys
  • Export Image Sequence
  • File Encryption
  • Add Watermark
  • Upgrade to Beta Version

性能优化

  • Use Performance Panel
  • PAG File Optimization

移动端进阶

  • Common API Overview
  • Use PAGImageView
  • Video Replacement
  • Play Audio
  • Text Layer Description
  • Use Encripted File
  • Export To Video
  • SDK Authentication

Web 进阶

  • SDK Installation
  • Load PAG File
  • Play PAG File
  • Platform Capabilities
  • Use WebWorker

API 参考

  • API Document

视频教程

  • PAG Workflow
  • File Optimization Best Practices
  • Use PAGExporter Panel
  • PAG Online Q&A

资源下载

  • PAGViewer Installer
  • PAG Test Files
  • PAG Demo Projects
  • China LiveVideoStackCon2022
  • PAG Conversion Tool
  • PAG File Format Spec

TAVMedia

  • Introduction to TAVMedia
  • TAVMedia Quick access
  • Common API Overview

其他

  • From Lottie To PAG
  • PAG Dictionary

Play Audio


TheAG SDK is a dedicated component for rendering effects. However, please note that the Community Edition does not support audio and video-related content. If you require audio play functionality, we recommend utilizing the PAG Enterprise Edition.

The PAG Enterprise Edition (with a movie suffix in the package name) incorporates the Movie function, enabling users to effortlessly read and play audio. It supports playing the built-in audio in the PAG file, as well as the audio in videos filled with placeholder images. Users have the flexibility to directly use PAGView for play or process PCM audio data on their own.

If you export a PAG file containing audio, you can refer to Export Audio

Audio Player Component PAGView

The Enterprise Edition PAGView has integrated the audio play capability. It supports the play of audio from PAG files as well as video files that contain placeholder images.

The detailed documentation of PAGImage can be found in Android | iOS .

Get Audio Data

The PAGAudioReader class in the Enterprise Edition offers an interface for accessing audio frame data in PAGComposition. It allows you to obtain mixed audio data, which includes audio from PAG files as well as video files that contain placeholder images. The audio data format used is PCMSigned16.

Usage Examples

1、Build a PAGAudioReader instance

Code Examples

android:

// Get the reader instance of the specified audio parameter
int sampleRate = 48000;
int sampleCount = 1024;
int channels = 2;
PAGAudioReader reader = PAGAudioReader.Make(sampleRate, sampleCount, channels);

iOS:

// Get the reader instance of the specified audio parameter
NSInteger sampleRate = 48000;
NSInteger sampleCount = 1024;
NSInteger channels = 2;
CGFloat volume = 1.0f; // 0 ~ 1.0f
PAGAudioReader *reader = [PAGAudioReader MakeWithSampleRate:sampleRate sampleCount:sampleCount channels:channels volume:1.0f];

2、 Set PAGComposition instance

Code Examples

Android:

PAGAudioReader reader = PAGAudioReader.Make(sampleRate, sampleCount, channels);
PAGComposition composition = PAGFile.Load(getAssets(), selectedPAGFileName);
reader.setComposition(composition);

iOS:

PAGComposition *composition = [PAGFile Load:path];
[reader setComposition:composition];

3、seek(optional)

Android:

// Seek to the position of the 5th second
long positionUs = 5_000_000;
reader.seek(positionUs);

iOS:

NSInteger positionUs = 5*1000*1000;
[reader seek:positionUs];

4、Read audio

You can read one frame of audio through the readNextSample interface of PAGAudioReader and move it to the next frame simultaneously;

To read the complete audio data from a PAGComposition instance, you can simply loop through the readNextSample call until all audio data is read.

Because composition allows for real-time modification, when there is no audio data in the composition, the audioReader will still return audio frames but the data in the audio is 0.

Code Examples:

Android:

if (reader.isEmpty()) {
    // If reader.isEmpty() returns true, it indicates that the composition has no audio data.
    return;
}
// Read the audio data in a loop until the reading is complete
PAGAudioSample audioFrame;
while ((audioFrame = reader.readNextSample()) != null 
        && audioFrame.timestamp + audioFrame.duration < composition.duration()) {
    audioFrame = reader.readNextSample();
    playAudio(audioFrame);
}

iOS:

if ([reader isEmpty]) {
    //  If [reader isEmpty] returns true, it indicates that the composition has no audio data.
    return;
}
PAGAudioSample* audioFrame = nil;
while ((audioFrame = [reader readNextSample]) != null 
        && audioFrame.timestamp + audioFrame.duration < composition.duration) {
    audioFrame = reader.readNextSample();
    dealWithAudio(audioFrame);
}
← Video ReplacementText Layer Description →
  • Audio Player Component PAGView
  • Get Audio Data
    • Usage Examples
Address: Tencent Binhai Building, No. 33 Haitian Second Road, Nanshan District, Shenzhen, Guangdong Province, China.
TEL: 0755-86013388
QQ Group: 893379574
Copyright © 2018 - 2025 Tencent. All Rights Reserved.
Privacy Policy
公司地址:广东省深圳市南山区海天二路33号腾讯滨海大厦
联系电话:0755-86013388
QQ群:893379574
Copyright © 2018 - 2025 Tencent. All Rights Reserved.
隐私政策
Copyright © 2018 - 2025 Tencent. All Rights Reserved.
Address: Tencent Binhai Building, No. 33 Haitian Second Road, Nanshan District, Shenzhen, Guangdong Province, China.
TEL: 0755-86013388
QQ Group: 893379574
Privacy Policy
Copyright © 2018 - 2025 Tencent. All Rights Reserved.
公司地址:广东省深圳市南山区海天二路33号腾讯滨海大厦
联系电话:0755-86013388
QQ群:893379574
隐私政策