适用于 Flutter 的腾讯云点播上传 SDK
将此添加到包的 pubspec.yaml 文件中:
dependencies:
flutter_txugcupload: ^0.1.0
或
dependencies:
flutter_txugcupload:
git:
url: https://github.com/leanflutter/flutter_txugcupload.git
ref: main
您可以从命令行安装软件包:
$ flutter packages get
如果您在 Podfile
中使用 use_frameworks!
,请按以下示例进行修改你的 Podfile
文件。
# 省略上方非关键代码
target 'Runner' do
use_frameworks!
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
# If you use `use_frameworks!` in your Podfile,
# uncomment the below $static_framework array and also
# the pre_install section.
$static_framework = ['flutter_txugcupload']
pre_install do |installer|
Pod::Installer::Xcode::TargetValidator.send(:define_method, :verify_no_static_framework_transitive_dependencies) {}
installer.pod_targets.each do |pod|
if $static_framework.include?(pod.name)
def pod.build_type;
Pod::BuildType.static_library
end
end
end
end
end
# 省略下方非关键代码
实现一个视频上传进度监听器(TXVideoPublishListener)
class VideoPublishListener extends TXVideoPublishListener {
final Function(int uploadBytes, int totalBytes) onVideoPublishProgress;
final Function(TXPublishResult result) onVideoPublishComplete;
VideoPublishListener({
this.onVideoPublishProgress,
this.onVideoPublishComplete,
});
@override
void onPublishProgress(int uploadBytes, int totalBytes) {
if (this.onVideoPublishProgress == null) return;
this.onVideoPublishProgress(uploadBytes, totalBytes);
}
@override
void onPublishComplete(TXPublishResult result) {
if (this.onVideoPublishComplete == null) return;
this.onVideoPublishComplete(result);
}
}
上传视频
TXUGCPublish txUgcPublish = TXUGCPublish(customKey: '<customKey>');
TXPublishParam param = TXPublishParam(
videoPath: '<videoPath>',
signature: '<signature>',
);
txUgcPublish.setVideoPublishListener(VideoPublishListener(
onVideoPublishProgress: (uploadBytes, totalBytes) {
int progress = ((uploadBytes / totalBytes) * 100).toInt();
},
onVideoPublishComplete: (result) {
// 当 result.errCode 为 0 时即为上传成功,更多错误码请查看下方链接
// https://cloud.tencent.com/document/product/266/9539#.E9.94.99.E8.AF.AF.E7.A0.81
},
));
txUgcPublish.publishVideo(param);