I have a problem which is not understandable from my side because 1 month ago I used same codes and everything was working now it’s not working.
Here is the code and console error for video player element.
//Save Video Duration
let interval = 2000
let videoInterval;
import wixData from 'wix-data';
import wixUsers from 'wix-users';
let userId = wixUsers.currentUser.id;
$w.onReady(function () {
checkPrevProgress()
})
function checkPrevProgress() {
let videoSrc = $w('#courseVideo').src
wixData.query("AcademyUserVideoDatas")
.eq("userId", userId)
.eq("videoId", videoSrc)
.find()
.then((results) => {
if (results.items.length > 0) {
//if video progress was saved before
let firstItem = results.items[0];
let time = firstItem.videoDuration
$w('#courseVideo').seek(time)
} else {
//if user is new
}
})
.catch((err) => {
let errorMsg = err;
});
}
function saveVideoDuration() {
let videoId = $w('#courseVideo').src
let watchedTime = $w('#courseVideo').currentTime
wixData.query("AcademyUserVideoDatas")
.eq("userId", userId)
.eq("videoId", videoId)
.find()
.then((results) => {
let userVideoData = results.items[0];
if (results.items.length > 0) {
let saveVideoDuration = {
...userVideoData,
"videoDuration": watchedTime
}
wixData.update("AcademyUserVideoDatas", saveVideoDuration)
} else {
let saveVideoDuration = {
"userId": userId,
"videoId": videoId,
"videoDuration": watchedTime
}
wixData.insert("AcademyUserVideoDatas", saveVideoDuration)
}
})
.catch((err) => {
console.error("Son Video Süresi Kaydedilemedi:", err)
})
}
function onVideoPlay() {
videoInterval = setInterval(() => {
saveVideoDuration();
}, interval);
}
function onVideoPause() {
clearInterval(videoInterval)
}
$w("#courseVideo").onPlay((event) => {
onVideoPlay()
})
$w("#courseVideo").onPause((event) => {
onVideoPause()
})
I copied all code from this post: How to add a Netflix-like resume watching feature to your website. | Velo by Wix
And when I tried to use checkPrevProgress() function it’s not working every other functions are working.
Here is the console error.
There is no problem with database permissions or something about data it’s just not skip to the right duration.