使用setData存数据,但是AppData中的数据不更新是怎么回事啊?
Page({
// 链接可能会过期换成自己的就行
data:{
//"audioUrl": "https://dl.stream.qqmusic.qq.com/C4000026gMkr1L9tKN.m4a?guid=7840612806&vkey=4696DBD6111F38EC3D75D0F4FDF769B3736068A795CF585BA18DF3A4BCD8F83D0662B54D70F64934AF74A34C9A354AFF0AA4660CCE4C66F0&uin=&fromtag=120032",
videoUrl: "C:/Users/priesty/Desktop/caogao/test.mp4",
videoInfo: {},
canvasWidth: 0,
canvasHeight: 0,
fps: 0,
duration: 0,
imageList: [],
tempFilePath:"",
},
onLoad: function (){
console.log("开始"),
this.videoDecoderStart()
},
// async是异步的意思,会返回一个promise对象,而awite会等待这个async的promise完成 并将reslove的结果返回出来
/* async videoDecoderStart() { */
videoDecoderStart() {
// 自己选择视频
const that = this
/* var tempFilePath = await wx.chooseMedia( */
//const tempFilePath = wx.chooseMedia(
wx.chooseMedia({
mediaType: ['video'], //设置文件类型为视频
sourceType: ['album'],
success(res){
console.log(res); //这个能打印出来
console.log("结果")
if(res){
//that.data.duration = res.tempFiles[0].duration
//this.setData({
that.setData({ //在data维护一组数据 ,感觉没有存成功!!!!!!!!
tempFilePath: res.tempFiles[0].tempFilePath,
//duration : that.data.duration,
duration : res.tempFiles[0].duration,
canvasWidth: res.tempFiles[0].width,
canvasHeight: res.tempFiles[0].height
}, () => {
// 创建视频解析器
/* this.videoDecoder = wx.createVideoDecoder() */
that.videoDecoder = wx.createVideoDecoder()
const {
canvas,
context
} = that.initOffscreenCanvas(that.data.canvasWidth, that.data.canvasWidth)
that.videoDecoder.on("start", () => {
that.videoDecoder.seek(0)
that.timer = setInterval(() => {
that.getFrameData(canvas, context)
}, 300);
})
that.videoDecoder.on("seek", () => {})
that.videoDecoder.on("stop", () => {})
that.videoDecoder.start({
source: tempFilePath
})
})
}
console.log(that.data.duration)
console.log(that.data.tempFilePath) //能显示,但不能存进AppData ??????
console.log(that.data.canvasWidth)
console.log(that.data.canvasHeight)
}
})
//const tempFilePath = that.data.tempFilePath
console.log("选择")
console.log( that.data.tempFilePath) //这里也无法显示数据!!!!!显示未定义!!!!!为什么啊!!
}
}