SDK Name | VOD Upload SDK For Android |
Version | V1.2.9.0 |
SDK Introduce | Providing a scenario for end-users of an app to upload local videos to a cloud video on demand platform: |
Developer | Tencent Cloud Computing (Beijing) Co., Ltd. |
Download SDK | 1. Click to download the iOS upload Demo and source code, unzip the downloaded package, and you can see the Demo directory. 2. Upload the source code in the Demo/ugcupload directory. |
Demo/ugcupload (i.e., the ugcupload module) to your project directory. If required, you may manually modify the package name.Demo/ugcupload/build.gradle to add dependencies in your project:implementation 'com.qcloud.cos:cos-android-nobeacon:5.9.46'
ugcquic module to your project directory and make it a dependency of the ugcupload module. If you need to perform manual integration, you can add the following dependencies:implementation 'com.qcloud.cos:quic:1.5.46'
AndroidManifest.xml file:<uses-permission android:name="android.permission.INTERNET"/><uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/><uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);// your code......registerNetReceiver();}private void registerNetReceiver() {if (null == mNetWorkStateReceiver) {mNetWorkStateReceiver = new TVCNetWorkStateReceiver();IntentFilter intentFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);registerReceiver(mNetWorkStateReceiver, intentFilter);}}private void unRegisterNetReceiver() {if (null != mNetWorkStateReceiver) {unregisterReceiver(mNetWorkStateReceiver);}}@Overrideprotected void onDestroy() {super.onDestroy();// your code......unRegisterNetReceiver();}
TXUGCPublish mVideoPublish = new TXUGCPublish(this.getApplicationContext(), "independence_android")
mVideoPublish.setListener(new TXUGCPublishTypeDef.ITXVideoPublishListener() {@Overridepublic void onPublishProgress(long uploadBytes, long totalBytes) {mProgress.setProgress((int) (100*uploadBytes/totalBytes));}@Overridepublic void onPublishComplete(TXUGCPublishTypeDef.TXPublishResult result) {mResultMsg.setText(result.retCode + " Msg:" + (result.retCode == 0 ? result.videoURL : result.descMsg));}});
TXUGCPublishTypeDef.TXPublishParam param = new TXUGCPublishTypeDef.TXPublishParam();param.signature = "xxx";param.videoPath = "xxx";
int publishCode = mVideoPublish.publishVideo(param);
TXUGCPublish mVideoPublish = new TXUGCPublish(this.getApplicationContext(), "independence_android")
mVideoPublish.setListener(new TXUGCPublishTypeDef.ITXMediaPublishListener() {@Overridepublic void onMediaPublishProgress(long uploadBytes, long totalBytes) {mProgress.setProgress((int) (100*uploadBytes/totalBytes));}@Overridepublic void onMediaPublishComplete(TXUGCPublishTypeDef.TXMediaPublishResult mediaResult) {mResultMsg.setText(result.retCode + " Msg:" + (result.retCode == 0 ? result.videoURL : result.descMsg));}});
TXUGCPublishTypeDef.TXMediaPublishParam param = new TXUGCPublishTypeDef.TXMediaPublishParam();param.signature = "xxx";param.mediaPath = "xxx";
int publishCode = mVideoPublish.publishMedia(param);
TXUGCPublishTypeDef.TXPublishParam param = new TXUGCPublishTypeDef.TXPublishParam();param.signature = "xxx";param.videoPath = "xxx";param.coverPath = "xxx";
cancelublish() interface of TXUGCPublish.mVideoPublish.canclePublish();
publishVideo method of TXUGCPublish again.enableResume parameter in the upload settings is the switch for breakpoint resume, which is enabled by default.TXUGCPublishOptCenter.getInstance().prepareUpload(signature) when your app starts. The pre-upload module will cache the<domain name, IP> mapping table and the optimal upload region locally. If network broadcasts have been dynamically registered previously, upon subscription to network switches, the cache will be cleared and automatically refreshed.enableHTTPS parameter in TXPublishParam to true. By default, it is set to false.TXUGCPublishTypeDef.TXPublishParam param = new TXUGCPublishTypeDef.TXPublishParam();param.enableHttps = true;
setIsDebug method of TXUGCPublish. By default, it is enabled. When enabled, it will print logcat logs and also save the logs to the app's private directory.// false Disable loggingmTXUGCPublish.setIsDebug(false);
TXUGCPublishParameter Name | Parameter Description | Type | Required |
context | application context | Context | YES |
customKey | Used to distinguish different users, it is recommended to use the App's account ID for easier subsequent issue tracking. | String | NO |
TXUGCPublish.setAppIdParameter Name | Parameter Description | Type | Required |
appId | vod appId。 | int | YES |
TXUGCPublish.publishVideoParameter Name | Parameter Description | Type | Required |
param | upload params. | TXUGCPublishTypeDef.TXPublishParam | YES |
TXUGCPublishTypeDef.TXPublishParamParameter Name | Parameter Description | Type | Required |
signature | String | YES | |
videoPath | Local video file path. | String | YES |
coverPath | Local cover file path, default without cover file. | String | NO |
enableResume | Whether to enable resuming from the breakpoint, default is enabled. | boolean | NO |
enableHttps | Whether to enable HTTPS, default is disabled. | boolean | NO |
fileName | The name of the video file uploaded to Tencent Cloud, if not filled, the default is the local file name. | String | NO |
enablePreparePublish | Whether to enable the pre-upload mechanism, default is enabled. The pre-upload mechanism can significantly improve the upload quality of files | boolean | NO |
sliceSize | Chunk size, supports a minimum of 1MB and a maximum of 10MB, default is the uploaded file size divided by 10 | long | NO |
concurrentCount | The maximum number of concurrent uploads for chunked uploads, default is 4. | int | NO |
trafficLimit | The speed limit value setting range is 819200 ~ 838860800, that is, 100KB/s ~ 100MB/s. If it exceeds this range, a 400 error will be returned. It is not recommended to set this value too small to prevent timeouts. -1 indicates no speed limit. | long | NO |
uploadResumeController | The resume controller, which can be customized to calculate and save the resume key values, defaults to using MD5 to calculate the file key values. | IUploadResumeController | NO |
TXUGCPublish.setListenerParameter Name | Parameter Description | Type | Required |
listener | Upload progress and result callback subscription. | TXUGCPublishTypeDef.ITXVideoPublishListener | YES |
TXUGCPublishTypeDef.ITXVideoPublishListener.onPublishProgressParameter Name | Parameter Description | Type |
uploadBytes | The number of bytes uploaded. | long |
totalBytes | Total number of bytes. | long |
TXUGCPublishTypeDef.ITXVideoPublishListener.onPublishCompleteParameter Name | Parameter Description | Type |
result | upload result | TXUGCPublishTypeDef.TXPublishResult |
TXUGCPublishTypeDef.TXPublishResultParameter Name | Parameter Description | Type |
retCode | result code | int |
descMsg | Error description for upload failure. | String |
videoId | Vod video file ID. | String |
videoURL | Video storage address. | String |
coverURL | Cover storage address. | String |
TXUGCPublishOptCenter.prepareUploadParameter Name | Parameter Description | Type | Required |
signature | String | YES |
TXUGCPublishParameter Name | Parameter Description | Type | Required |
context | application context | Context | YES |
customKey | Used to distinguish different users, it is recommended to use the App's account ID for easier subsequent issue tracking. | String | NO |
TXUGCPublish.setAppIdParameter Name | Parameter Description | Type | Required |
appId | vod appId。 | int | YES |
TXUGCPublish.publishMediaParameter Name | Parameter Description | Type | Required |
param | upload params. | TXUGCPublishTypeDef.TXMediaPublishParam | YES |
TXUGCPublishTypeDef.TXMediaPublishParamParameter Name | Parameter Description | Type | Required |
signature | String | YES | |
mediaPath | Local image file path. | String | YES |
enableResume | Whether to enable resuming from the breakpoint, default is enabled. | boolean | NO |
enableHttps | Whether to enable HTTPS, default is disabled. | boolean | NO |
fileName | The name of the video file uploaded to Tencent Cloud, if not filled, the default is the local file name. | String | NO |
enablePreparePublish | Whether to enable the pre-upload mechanism, default is enabled. The pre-upload mechanism can significantly improve the upload quality of files | boolean | NO |
sliceSize | Chunk size, supports a minimum of 1MB and a maximum of 10MB, default is the uploaded file size divided by 10 | long | NO |
concurrentCount | The maximum number of concurrent uploads for chunked uploads, default is 4. | int | NO |
trafficLimit | The speed limit value setting range is 819200 ~ 838860800, that is, 100KB/s ~ 100MB/s. If it exceeds this range, a 400 error will be returned. It is not recommended to set this value too small to prevent timeouts. -1 indicates no speed limit. | long | NO |
uploadResumeController | The resume controller, which can be customized to calculate and save the resume key values, defaults to using MD5 to calculate the file key values. | IUploadResumeController | NO |
TXUGCPublish.setListenerParameter Name | Parameter Description | Type | Required |
listener | Upload progress and result callback subscription. | TXUGCPublishTypeDef.ITXMediaPublishListener | YES |
TXUGCPublishTypeDef.ITXMediaPublishListener.onPublishProgressParameter Name | Parameter Description | Type |
uploadBytes | The number of bytes uploaded. | long |
totalBytes | Total number of bytes. | long |
TXUGCPublishTypeDef.ITXMediaPublishListener.onPublishCompleteParameter Name | Parameter Description | Type |
result | upload result | TXUGCPublishTypeDef.TXPublishResult |
TXUGCPublishTypeDef.TXMediaPublishResultParameter Name | Parameter Description | Type |
retCode | result code | int |
descMsg | Error description for upload failure. | String |
mediaId | vod media file ID. | String |
mediaURL | Media resource storage address. | String |
TXUGCPublishOptCenter.prepareUploadParameter Name | Parameter Description | Type | Required |
signature | String | YES |
TXUGCPublishTypeDef.ITXVideoPublishListener\\ITXMediaPublishListener interface to subscribe to the status of video uploading. Therefore, you can use the retCode in TXUGCPublishTypeDef.TXPublishResult\\TXMediaPublishResult to determine the situation of video uploading.Status code | Corresponding constant in TVCConstants | Meaning |
0 | NO_ERROR | Upload successful. |
1001 | ERR_UGC_REQUEST_FAILED | Request upload failed, usually due to an expired or invalid client signature, requiring the app to reapply for a signature. |
1002 | ERR_UGC_PARSE_FAILED | Failed to parse request information. |
1003 | ERR_UPLOAD_VIDEO_FAILED | Failed to upload video. |
1004 | ERR_UPLOAD_COVER_FAILED | Failed to upload cover. |
1005 | ERR_UGC_FINISH_REQUEST_FAILED | Failed to end upload request. |
1006 | ERR_UGC_FINISH_RESPONSE_FAILED | End upload response error. |
1007 | ERR_CLIENT_BUSY | Client is busy (object cannot handle more requests). |
1008 | ERR_FILE_NOEXIT | Uploaded file does not exist. |
1009 | ERR_UGC_PUBLISHING | Video is currently being uploaded. |
1010 | ERR_UGC_INVALID_PARAM | Video is currently being uploaded. |
1012 | ERR_UGC_INVALID_SIGNATURE | Video upload signature is empty. |
1013 | ERR_UGC_INVALID_VIDOPATH | Path to video file is empty. |
1014 | ERR_UGC_INVALID_VIDEO_FILE | Video file does not exist at current path. |
1015 | ERR_UGC_FILE_NAME | Video upload file name is too long (exceeds 40 characters) or contains special characters. |
1016 | ERR_UGC_INVALID_COVER_PATH | Incorrect cover path for video file, file does not exist. |
1017 | ERR_USER_CANCEL | User canceled upload. |
1020 | ERR_UPLOAD_SIGN_EXPIRED | Signature expired. |
Feedback