<template>
<view class="page">
<view @click="confirmMusicClip"> 裁剪</view>
</view>
</template>
<script>
const app = getApp();
// #ifdef APP-VUE
import {
executeFFmpeg
} from '@/uni_modules/sn-uts-ffmpeg'
// #endif
export default {
components: {
},
data() {
return {
fullSongFile: '',
clipSongOutputDir: '',
}
},
watch: {
},
computed:{
},
onLoad(options) {
this.downloadMusic()
},
onShow() {
},
onHide() {
},
onUnload() {
},
created() {
},
beforeDestroy() {
},
methods: {
downloadMusic(){
let mp3_file ="https://cdn.hunque.cn/storage/default/audio_files/34841fb3ba56b93315c3dd5df892cd51fa71d8e6.mp3"
let fileName = mp3_file.split('/').pop()
let that = this
uni.showLoading({
title: `正在加载`,
})
console.warn("downloadMusic",mp3_file,fileName)
uni.downloadFile({
url: `${mp3_file}`,
success(e) {
let {tempFilePath} = e
console.warn('tempFilePath',tempFilePath)
uni.hideLoading()
that.fullSongFile = tempFilePath
}
})
},
// 确认使用剪辑的音乐
confirmMusicClip(){
let that = this
let {
fullSongFile,
clipSongOutputDir,
} = this
let time = new Date()/1
let filePath = `${clipSongOutputDir}${time}.mp3`
let real_path = plus.io.convertLocalFileSystemURL(fullSongFile)
console.warn("confirmMusicClip",real_path,filePath)
uni.showLoading({
title: `正在剪裁`,
mask: true,
})
let filter = ``
let demoBeginTime = "00:10"
let demoEndTime = "00:15"
let cmd = `-i ${real_path} -ss ${demoBeginTime} -to ${demoEndTime} ${filter} -f mp3 -acodec copy ${filePath}`
console.warn("ffmpeg",cmd)
executeFFmpeg(cmd, res => {
let {state, returnCode} = res
console.warn("FFmpeg完成回调:",res);
}, res => {
//
console.log(`FFmpeg统计回调`,res)
}, res => {
console.log("开始任务回调:" ,res);
}, res => {
console.log("log回调:" ,res);
}, 6000)
// console.log('位置',fullSongFile, filePath)
// uni.hideLoading()
// return
console.warn("filePath",filePath)
uni.hideLoading()
return false;
},
}
}
</script>
<style>
.page{
width: 750rpx;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
</style>
0 个回复