当前位置:网站首页>Tiktok practice ~ upload and release app video
Tiktok practice ~ upload and release app video
2022-06-24 23:36:00 【gblfy】

List of articles
One 、API read
1. Select or capture video
find uni.chooseVideo(OBJECT)API,
Select or capture a video file :https://uniapp.dcloud.net.cn/api/media/video.html#choosevideo
2. Cloud functions API~ Upload files
Use of api:uniCloud.uploadFile(Object uploadFileOptions)
uniCloud API file

3. Video cut frame
purpose : Video frame cut as video cover
Alibaba cloud service for video frame cutting 
Video framing service
Alibaba cloud video frames 
Two 、App End video upload process
2.1. Upload flowchart

2.2. Process brief
- 1. Verify user login status , Not logged in , Then jump to the login page to log in , The login process continues .
- 2. Click the middle release button
- 3. Select or capture video , Click on the confirmation
- 4. Jump to the short video publishing page with the file information
- 5. When the short video publishing page is loaded , Receive video file information , Parsing file information
- 6. Configuration file path and cloud file name
- 7. Call cloud function , Perform short video cloud upload
- 8. Short video uploading process , The progress bar is dynamically displayed according to the actual upload progress
- 9. Short video upload completed , Call alicloud video framing service , Make video frame cut cover
- 10. Short video message encapsulation
- 11. Supplement the uploaded content
- 12. Post a short video , Call the back-end interface service
- 13. Short video file information , Brief treatment , Execute stock drop processing
3、 ... and 、 Front end source code practice
3.1. choice / Take a short video
// Listen for the click event of the middle button
uni.onTabBarMidButtonTap(()=>{
// Cannot publish video without logging in
var myUserInfo = getApp().getUserInfoSession();
if (myUserInfo == null) {
uni.showToast({
duration: 3000,
title: " Please log in ~",
icon: "none"
});
uni.navigateTo({
url: "../loginRegist/loginRegist",
animationType: "slide-in-bottom",
success() {
me.loginWords = " Please log in "
}
});
return;
}
// console.log('onTabBarMidButtonTap');
uni.switchTab({
url: "../me/me"
});
uni.chooseVideo({
sourceType: ['album'],
success(e) {
uni.navigateTo({
url: "/pages/publish/publish?fileObjectEvent=" + JSON.stringify(e)
})
/** * Or use uniCloud, Finish uploading on the client , Reduce links , Because the file is large , The communication link and time consumption are doubled */
var times = new Date().getTime();
}
})
});
3.2. Short video upload
// Triggered when the current page is loaded
onLoad(params) {
var me = this;
this.statusBarHeight = system.statusBarHeight;
this.screenWidth = system.screenWidth;
// File event object passed from the previous page , It contains the video content selected from the album
var fileObjectEvent = JSON.parse(params.fileObjectEvent);
var times = new Date().getTime();
uniCloud.uploadFile({
// File object to upload -> Get temporary video path
filePath: fileObjectEvent.tempFilePath,
// When using alicloud ,cloudPath Is the cloud file name
// Customize according to specific business
cloudPath: times + '.mp4',
// Progress bar Events
onUploadProgress(progressEvent) {
var percentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total);
// This value is the percentage of dynamic change during video uploading , To show the specific progress of uploading
me.percentCompleted = percentCompleted;
},
// Process operation after uploading
success(f) {
// Get the video path
var videoUrlTemp = f.filePath;
// Get video ID
var videoUrl = f.fileID;
// Get video parameters
me.tempFilePath = videoUrlTemp;
me.videoUrl = videoUrl;
me.tempCover = videoUrl + "?x-oss-process=video/snapshot,t_1,f_jpg,ar_auto"; // Cut frame
me.width = fileObjectEvent.width;
me.height = fileObjectEvent.height;
}
});
},
3.3. Progress bar page
<!-- Progress bar -->
<view style="marginTop:60rpx;display: flex;flex-direction: column;justify-content: center;"
v-if="percentCompleted != 100">
<progress :percent="percentCompleted" stroke-width="3" activeColor="#ef274d" backgroundColor="#F1F1F1"
:style="{screenWidth: screenWidth + 'px'}" />
<text style="color: #F1F1F1;font-size: 16px;text-align: center;margin-top: 20px;"
:style="{screenWidth: screenWidth + 'px'}"> Video uploading ~ Please be patient ~~</text>
<image mode="aspectFit" src="../../static/images/loading-4.gif"
style="width: 600rpx;height: 600rpx;align-self: center;">
</view>
3.4. Add short video content
<textarea class="vlog-content" placeholder-style="color: #9798a0;" placeholder=" Add appropriate title content " :value="title"
:model="title" maxlength="60" @input="typingContent" confirm-type="done"></textarea>
3.5. Video release
<view :class="{'btn-publish':!publichTouched, 'btn-publish-touched': publichTouched}"
style="margin-top: 30rpx;height: 90rpx;display: flex;justify-content: center;border-radius: 20px;"
@touchstart="touchstartPublich" @touchend="touchendPublich" @click="doPublich">
<text style="color: #e6e6e6;font-size: 18px;align-self: center;font-weight: 500;"> Release Vlog</text>
</view>
doPublich() {
var me = this;
var userId = getApp().getUserInfoSession().id;
var vlog = {
"vlogerId": userId,
"url": me.videoUrl,
"cover": me.tempCover,
"title": me.title,
"width": me.width,
"height": me.height
};
// Release video
var serverUrl = app.globalData.serverUrl;
uni.request({
method: "POST",
header: {
headerUserId: userId,
headerUserToken: app.getUserSessionToken()
},
url: serverUrl + "/vlog/publish",
data: vlog,
success(result) {
if (result.data.status == 200) {
uni.showToast({
title: " Successful release !",
icon: "none"
})
uni.navigateBack({
delta: 1,
animationType: 'zoom-fade-in',
animationDuration: 1000
});
uni.switchTab({
url: "../me/me"
})
} else {
uni.showToast({
title: result.data.msg,
icon: "none",
duration: 3000
});
}
}
});
},
3.6. Video preview
preview() {
uni.navigateTo({
url: "/pages/publish/preview?videoUrl=" + this.videoUrl + "&width=" + this.width + "&height=" +
this.height,
animationType: 'slide-in-bottom',
animationDuration: 500
})
},
Four 、 Back end source code practice
4.1. Short video release
/** * Release vlog video * * @param vlogBO * @return */
@PostMapping("publish")
public GraceJSONResult publish(@RequestBody VlogBO vlogBO) {
vlogService.createVlog(vlogBO);
return GraceJSONResult.ok();
}
4.2. Logical processing
/** * Release vlog video * * @param vlogBO */
@Transactional
@Override
public void createVlog(VlogBO vlogBO) {
// video ID
String vid = sid.nextShort();
Vlog vlog = new Vlog();
BeanUtils.copyProperties(vlogBO, vlog);
vlog.setId(vid);
vlog.setLikeCounts(0);
vlog.setCommentsCounts(0);
vlog.setIsPrivate(YesOrNo.NO.type);
vlog.setCreatedTime(new Date());
vlog.setUpdatedTime(new Date());
vlogMapper.insert(vlog);
}
5、 ... and 、 Appreciation of renderings
5.1.


边栏推荐
- Bubble sort
- Using external Libpcap library on ARM platform
- 7-2 后序+中序序列构造二叉树
- Pseudo original intelligent rewriting API Baidu - good collection
- File contains vulnerability issues
- Understanding openstack network
- Basic data type
- R语言使用MatchIt包进行倾向性匹配分析、使用match.data函数构建匹配后的样本集合、对匹配后的样本的不同分组对应的目标变量的均值进行Welch双样本t检验分析、双独立样本t检验
- 257. 关押罪犯
- [JS] - [tree] - learning notes
猜你喜欢

Volcano becomes spark default batch scheduler

抖音实战~项目关联UniCloud

Still using simpledateformat for time formatting? Be careful of project collapse

Adding, deleting, querying and modifying MySQL tables

【UVM入门 ===> Episode_8 】~ Sequence 和 Sequencer、Sequence 层次化

Design and practice of vivo server monitoring architecture

Installation and deployment of ganglia

我的为人处事真的有问题吗?

Why is it that the "Zhongtai" that was originally eaten by civil engineering is no longer fragrant?

Morris traversal
随机推荐
Harmonyos accessing database instances (3) -- use ORM bee to test how good harmonyos is
当初吃土建起来的“中台”,现在为啥不香了?
R语言dplyr包group_by函数和summarise_at函数计算dataframe计算不同分组的计数个数和均值(Summarise Data by Categorical Variable)
7-6 铺设油井管道
R语言使用MatchIt包进行倾向性匹配分析、使用match.data函数构建匹配后的样本集合、对匹配后的样本的不同分组对应的目标变量的均值进行Welch双样本t检验分析、双独立样本t检验
Huawei machine learning service speech recognition function enables applications to paint "sound" and color
Inventory of data governance status of six major banks: governance architecture, data standards and data middle office (April 2022)
Classic interview questions and answers for embedded engineers
R语言使用nnet包的multinom函数构建无序多分类logistic回归模型、使用AIC函数比较两个模型的AIC值的差异(简单模型和复杂模型)
376. 機器任務
7-7 求解众数问题
年薪百万,7年测试经验:守在一个还算不错的赛道,慢慢积累,等风来
去商场逛街
Latest development of jetpack compose
websocket长链接压测
7-8 循环日程安排问题
Quickly build KVM virtual machine on # yyds dry goods inventory # physical machine
2021-2022中国金融数字化“新”洞察行业研究报告
Andersen Global借助巴勒斯坦成员公司加强中东平台
Spark's wide dependence and narrow dependence yyds dry goods inventory