PluginProbe
StreamCast – bring live radio to your site with a sleek player / 2.2.3
StreamCast – bring live radio to your site with a sleek player v2.2.3
2.4.5 2.4.4 trunk 1.0 1.1 2.0.0 2.1.10 2.1.2 2.1.4 2.1.5 2.1.8 2.2.1 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 All 29 releases
streamcast / public / js / script.js

script.js in StreamCast – bring live radio to your site with a sleek player 2.2.3, at public/js/script.js

71 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 *
3 * @param {*} time
4 * @returns
5 */
6 function toHHMMSS(time) {
7 var sec_num = parseInt(time, 10); // don't forget the second param
8 var hours = Math.floor(sec_num / 3600);
9 var minutes = Math.floor((sec_num - hours * 3600) / 60);
10 var seconds = sec_num - hours * 3600 - minutes * 60;
11
12 if (hours < 10) {
13 hours = "0" + hours;
14 }
15 if (minutes < 10) {
16 minutes = "0" + minutes;
17 }
18 if (seconds < 10) {
19 seconds = "0" + seconds;
20 }
21 return minutes + ":" + seconds;
22 }
23
24 document.addEventListener("DOMContentLoaded", function () {
25 const streamCastPlayers = document.querySelectorAll(".sc_radio");
26
27 streamCastPlayers.forEach((item) => {
28 const audio = item.querySelector(".player");
29 const player = new Plyr(audio, {
30 controls: ["play", "current-time", "mute", "volume"],
31 });
32 player.on("ready", function () {
33 const iconPressed = item.querySelector(".icon--pressed");
34 const iconNotPressed = item.querySelector(".icon--not-pressed");
35 const timeEl = item.querySelector(".plyr__time--current");
36 let playing = true;
37 let currentTime = player.currentTime;
38
39 player.on("pause", function (e) {
40 player.play();
41 currentTime = e.timeStamp;
42 if (playing) {
43 player.muted = true;
44 playing = false;
45 iconNotPressed.style.display = "block";
46 iconPressed.style.display = "none";
47 } else {
48 iconNotPressed.style.display = "none";
49 iconPressed.style.display = "block";
50 playing = true;
51 player.muted = false;
52 }
53 });
54
55 player.on("play", function () {
56 // console.log(player.volume);
57 if (player.volume == 0) {
58 player.volume = 0.5;
59 }
60 if (playing) {
61 player.muted = false;
62 }
63 });
64
65 player.on("timeupdate", function (e) {
66 timeEl.innerText = toHHMMSS(playing ? e.timeStamp / 1000 : currentTime / 1000);
67 });
68 });
69 });
70 });
71