Skip to content

Commit

Permalink
Optimize media session calling
Browse files Browse the repository at this point in the history
  • Loading branch information
reynaldichernando committed Nov 16, 2024
1 parent 396c80a commit 06a3af9
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions components/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ export default function Main() {

setPosition(videoRef.current.currentTime);
setDuration(videoRef.current.duration);

navigator.mediaSession.setPositionState({ duration: audioRef.current.duration, position: audioRef.current.currentTime });
} catch (error) {
}
}, 300);
Expand Down Expand Up @@ -139,12 +137,15 @@ export default function Main() {
};

const stopTrack = () => {
if (!videoRef.current || !audioRef.current) { return; }
videoRef.current.pause();
audioRef.current.pause();
if (videoRef.current) {
videoRef.current.pause();
videoRef.current.currentTime = 0;
}

videoRef.current.currentTime = 0;
audioRef.current.currentTime = 0;
if (audioRef.current) {
audioRef.current.pause();
audioRef.current.currentTime = 0;
}

setIsPlaying(false);
};
Expand All @@ -168,11 +169,13 @@ export default function Main() {
};

const seekTo = (time: number) => {
if (!audioRef.current || !videoRef.current) { return; }
audioRef.current.load();
if (audioRef.current) {
audioRef.current.currentTime = time;
}

audioRef.current.currentTime = time;
videoRef.current.currentTime = time;
if (videoRef.current) {
videoRef.current.currentTime = time;
}
}

const handleTogglePlay = () => {
Expand Down

0 comments on commit 06a3af9

Please sign in to comment.