{"id":2,"date":"2026-11-16T14:18:42","date_gmt":"2026-11-16T14:18:42","guid":{"rendered":"https:\/\/teleradioitalia.it\/?page_id=2"},"modified":"2026-11-21T18:20:44","modified_gmt":"2026-11-21T18:20:44","slug":"sample-page","status":"publish","type":"page","link":"https:\/\/teleradioitalia.it\/","title":{"rendered":""},"content":{"rendered":"\n<script>\n(function() {\n  const JSON_URL = \"https:\/\/nrf1.newradio.it:8080\/json\/stream\/9682\";\n  const STREAM_CANDIDATES = [\n    \"https:\/\/nrf1.newradio.it:9682\/stream.mp3\",\n    \"https:\/\/nrf1.newradio.it\/stream\/9682\/stream.mp3\",\n    \"https:\/\/nrf1.newradio.it\/stream\/9682\"\n  ];\n\n  const audio = new Audio();\n  audio.preload = \"none\";\n  audio.volume = 0.9;\n\n  let isPlaying = false;\n  let userStopped = false;\n  let currentUrlIndex = 0;\n  let playAttemptId = 0;\n\n  const coverEl = document.getElementById(\"tri-cover\");\n  const titleEl = document.getElementById(\"tri-title\");\n  const artistEl = document.getElementById(\"tri-artist\");\n  const badgeEl = document.getElementById(\"tri-live-badge\");\n  const metaInfoEl = document.getElementById(\"tri-meta-info\");\n  const statusEl = document.getElementById(\"tri-status\");\n  const playBtn = document.getElementById(\"tri-play-btn\");\n  const volEl = document.getElementById(\"tri-volume\");\n  const historyWrap = document.getElementById(\"tri-history-wrap\");\n  const historyList = document.getElementById(\"tri-history-list\");\n\n  function onFirstInteraction(e) {\n    removeUnlockListeners();\n    if (e.target === playBtn || playBtn.contains(e.target)) return;\n    if (!isPlaying && !userStopped) startStream(false, currentUrlIndex);\n  }\n\n  function addUnlockListeners() {\n    document.addEventListener(\"click\", onFirstInteraction);\n    document.addEventListener(\"keydown\", onFirstInteraction);\n  }\n\n  function removeUnlockListeners() {\n    document.removeEventListener(\"click\", onFirstInteraction);\n    document.removeEventListener(\"keydown\", onFirstInteraction);\n  }\n\n  function startStream(isAutoplay, idx) {\n    const urlIndex = typeof idx === \"number\" ? idx : 0;\n    const url = STREAM_CANDIDATES[urlIndex];\n    const myAttempt = ++playAttemptId;\n\n    statusEl.textContent = \"Connessione...\";\n    audio.pause();\n    audio.src = url;\n    audio.load();\n\n    audio.play().then(function() {\n      if (myAttempt !== playAttemptId || userStopped) return;\n      currentUrlIndex = urlIndex;\n      isPlaying = true;\n      removeUnlockListeners();\n      playBtn.textContent = \"\u25a0 STOP\";\n      statusEl.textContent = \"Riproduzione attiva\";\n    }).catch(function(err) {\n      if (myAttempt !== playAttemptId || userStopped) return;\n\n      \/\/ Blocco autoplay del browser: l'URL pu\u00f2 essere valido, attende interazione utente\n      if (err && err.name === \"NotAllowedError\") {\n        audio.removeAttribute(\"src\");\n        audio.load();\n        isPlaying = false;\n        playBtn.textContent = \"\u25b6 ASCOLTA\";\n        statusEl.textContent = \"Clicca sulla pagina o premi ASCOLTA\";\n        addUnlockListeners();\n        return;\n      }\n\n      \/\/ Errore reale di stream: prova il prossimo indirizzo disponibile\n      if (urlIndex + 1 < STREAM_CANDIDATES.length) {\n        startStream(isAutoplay, urlIndex + 1);\n        return;\n      }\n\n      audio.removeAttribute(\"src\");\n      audio.load();\n      isPlaying = false;\n      playBtn.textContent = \"\u25b6 ASCOLTA\";\n      statusEl.textContent = \"Errore avvio stream\";\n      console.warn(\"Tutti gli URL stream hanno fallito:\", err);\n    });\n  }\n\n  function stopStream() {\n    userStopped = true;\n    playAttemptId++;\n    removeUnlockListeners();\n    audio.pause();\n    audio.removeAttribute(\"src\");\n    audio.load();\n    isPlaying = false;\n    playBtn.textContent = \"\u25b6 ASCOLTA\";\n    statusEl.textContent = \"In pausa\";\n  }\n\n  async function updateMetadata() {\n    try {\n      const res = await fetch(JSON_URL, { cache: \"no-store\" });\n      if (!res.ok) throw new Error(\"HTTP \" + res.status);\n      const data = await res.json();\n\n      if (data.status === false) {\n        badgeEl.textContent = \"OFFLINE\";\n        badgeEl.classList.add(\"is-offline\");\n      } else {\n        badgeEl.textContent = \"IN ONDA\";\n        badgeEl.classList.remove(\"is-offline\");\n      }\n\n      const infoParts = [];\n      if (data.bitrate) infoParts.push(data.bitrate + \" kbps\");\n      if (data.format) infoParts.push(data.format);\n      metaInfoEl.textContent = infoParts.join(\" \u2022 \");\n\n      let rawTrack = (data.nowplaying || \"\").replace(\/^Now Playing:\\s*\/i, \"\").trim();\n      let title = \"Tele Radio Italia\";\n      let artist = \"In diretta\";\n\n      if (rawTrack) {\n        const sep = rawTrack.indexOf(\" - \");\n        if (sep !== -1) {\n          artist = rawTrack.slice(0, sep).trim();\n          title = rawTrack.slice(sep + 3).trim();\n        } else {\n          title = rawTrack;\n          artist = \"Tele Radio Italia\";\n        }\n      }\n\n      titleEl.textContent = title;\n      artistEl.textContent = artist;\n\n      const art = data.coverart || data.art || \"\";\n      if (art) {\n        coverEl.src = art;\n        coverEl.style.display = \"block\";\n      }\n\n      const hist = Array.isArray(data.history) ? data.history.slice(0, 5) : [];\n      if (hist.length > 0) {\n        historyList.innerHTML = \"\";\n        hist.forEach(function(item) {\n          const li = document.createElement(\"li\");\n          li.className = \"tri-history-item\";\n          li.textContent = typeof item === \"string\"\n            ? item\n            : (item.title || item.track || JSON.stringify(item));\n          historyList.appendChild(li);\n        });\n        historyWrap.style.display = \"block\";\n      }\n\n      if (\"mediaSession\" in navigator) {\n        navigator.mediaSession.metadata = new MediaMetadata({\n          title: title,\n          artist: artist,\n          album: \"Tele Radio Italia\",\n          artwork: art ? [{ src: art, sizes: \"512x512\", type: \"image\/jpeg\" }] : []\n        });\n      }\n    } catch (err) {\n      console.warn(\"Errore lettura metadati MediaCP:\", err);\n    }\n  }\n\n  playBtn.addEventListener(\"click\", function() {\n    if (isPlaying) {\n      stopStream();\n    } else {\n      userStopped = false;\n      removeUnlockListeners();\n      startStream(false, currentUrlIndex);\n    }\n  });\n\n  volEl.addEventListener(\"input\", function() {\n    audio.volume = parseFloat(volEl.value);\n  });\n\n  if (\"mediaSession\" in navigator) {\n    navigator.mediaSession.setActionHandler(\"play\", function() {\n      userStopped = false;\n      startStream(false, currentUrlIndex);\n    });\n    navigator.mediaSession.setActionHandler(\"pause\", stopStream);\n    navigator.mediaSession.setActionHandler(\"stop\", stopStream);\n  }\n\n  startStream(true, 0);\n  updateMetadata();\n  setInterval(updateMetadata, 15000);\n})();\n<\/script>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"743\" src=\"https:\/\/teleradioitalia.it\/wp-content\/uploads\/2026\/11\/cropped-Logo-Tele-Radio-Italia-1024x743.jpeg\" alt=\"\" class=\"wp-image-19\" style=\"width:714px;height:auto\" srcset=\"https:\/\/teleradioitalia.it\/wp-content\/uploads\/2026\/11\/cropped-Logo-Tele-Radio-Italia-1024x743.jpeg 1024w, https:\/\/teleradioitalia.it\/wp-content\/uploads\/2026\/11\/cropped-Logo-Tele-Radio-Italia-300x218.jpeg 300w, https:\/\/teleradioitalia.it\/wp-content\/uploads\/2026\/11\/cropped-Logo-Tele-Radio-Italia.jpeg 1600w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<div id=\"tri-radio-widget\">\n  <div class=\"tri-header\">\n    <img decoding=\"async\" id=\"tri-cover\" class=\"tri-cover\" src=\"\" alt=\"Copertina in onda\" style=\"display:none;\" \/>\n    <div class=\"tri-main\">\n      <div class=\"tri-badges\">\n        <span id=\"tri-live-badge\" class=\"tri-badge\">IN ONDA<\/span>\n        <span id=\"tri-meta-info\" class=\"tri-meta-info\"><\/span>\n        <span id=\"tri-status\" class=\"tri-status\">Avvio&#8230;<\/span>\n      <\/div>\n      <div id=\"tri-title\" class=\"tri-title\">Tele Radio Italia<\/div>\n      <div id=\"tri-artist\" class=\"tri-artist\">In diretta<\/div>\n      <div class=\"tri-controls\">\n        <button id=\"tri-play-btn\" type=\"button\" class=\"tri-btn\" aria-label=\"Avvia o ferma la radio\">\u25b6 ASCOLTA<\/button>\n        <div class=\"tri-vol-wrap\">\n          <span class=\"tri-vol-icon\">\ud83d\udd0a<\/span>\n          <input id=\"tri-volume\" type=\"range\" min=\"0\" max=\"1\" step=\"0.05\" value=\"0.9\" aria-label=\"Volume\" \/>\n        <\/div>\n      <\/div>\n    <\/div>\n  <\/div>\n  <div id=\"tri-history-wrap\" class=\"tri-history-wrap\" style=\"display:none;\">\n    <div class=\"tri-history-title\">Ultimi brani trasmessi<\/div>\n    <ul id=\"tri-history-list\" class=\"tri-history-list\"><\/ul>\n  <\/div>\n<\/div>\n<style>\n#tri-radio-widget { font-family: system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, sans-serif; background: #141821; color: #f3f4f6; border-radius: 14px; padding: 20px; max-width: 720px; margin: 20px auto; box-shadow: 0 10px 28px rgba(0,0,0,0.25); box-sizing: border-box; }\n#tri-radio-widget * { box-sizing: border-box; }\n#tri-radio-widget .tri-header { display: flex; gap: 18px; align-items: center; }\n#tri-radio-widget .tri-cover { width: 116px; height: 116px; border-radius: 10px; object-fit: cover; background: #232938; flex-shrink: 0; }\n#tri-radio-widget .tri-main { flex: 1; min-width: 0; }\n#tri-radio-widget .tri-badges { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; flex-wrap: wrap; }\n#tri-radio-widget .tri-badge { display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: 0.06em; padding: 3px 8px; border-radius: 999px; background: #dc2626; color: #ffffff; text-transform: uppercase; }\n#tri-radio-widget .tri-badge.is-offline { background: #4b5563; }\n#tri-radio-widget .tri-meta-info, #tri-radio-widget .tri-status { font-size: 12px; color: #9ca3af; }\n#tri-radio-widget .tri-title { font-size: 20px; font-weight: 700; line-height: 1.25; color: #ffffff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }\n#tri-radio-widget .tri-artist { font-size: 15px; color: #d1d5db; margin-top: 2px; margin-bottom: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }\n#tri-radio-widget .tri-controls { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }\n#tri-radio-widget .tri-btn { background: #dc2626; color: #ffffff; border: none; border-radius: 8px; padding: 10px 18px; font-size: 14px; font-weight: 700; cursor: pointer; transition: background 0.15s ease; }\n#tri-radio-widget .tri-btn:hover { background: #b91c1c; }\n#tri-radio-widget .tri-vol-wrap { display: flex; align-items: center; gap: 8px; }\n#tri-radio-widget #tri-volume { width: 95px; accent-color: #dc2626; cursor: pointer; }\n#tri-radio-widget .tri-history-wrap { margin-top: 16px; border-top: 1px solid #262d3d; padding-top: 14px; }\n#tri-radio-widget .tri-history-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: #9ca3af; margin-bottom: 10px; }\n#tri-radio-widget .tri-history-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }\n#tri-radio-widget .tri-history-item { display: flex; align-items: center; gap: 10px; font-size: 13px; background: #1b2130; padding: 7px 10px; border-radius: 8px; color: #e5e7eb; }\n@media (max-width: 560px) {\n  #tri-radio-widget .tri-header { flex-direction: column; text-align: center; }\n  #tri-radio-widget .tri-badges, #tri-radio-widget .tri-controls { justify-content: center; }\n  #tri-radio-widget .tri-title, #tri-radio-widget .tri-artist { white-space: normal; }\n}\n<\/style>\n<script>\n(function() {\n  const JSON_URL = \"https:\/\/nrf1.newradio.it:8080\/json\/stream\/9682\";\n  const STREAM_CANDIDATES = [\n    \"https:\/\/nrf1.newradio.it:9682\/stream.mp3\",\n    \"https:\/\/nrf1.newradio.it:9682\/stream\",\n    \"https:\/\/nrf1.newradio.it\/stream\/9682\/stream.mp3\",\n    \"https:\/\/nrf1.newradio.it\/stream\/9682\"\n  ];\n  const audio = new Audio();\n  audio.preload = \"none\";\n  audio.volume = 0.9;\n  let isPlaying = false;\n  let userStopped = false;\n  let currentUrlIndex = 0;\n  let playAttemptId = 0;\n  const coverEl = document.getElementById(\"tri-cover\");\n  const titleEl = document.getElementById(\"tri-title\");\n  const artistEl = document.getElementById(\"tri-artist\");\n  const badgeEl = document.getElementById(\"tri-live-badge\");\n  const metaInfoEl = document.getElementById(\"tri-meta-info\");\n  const statusEl = document.getElementById(\"tri-status\");\n  const playBtn = document.getElementById(\"tri-play-btn\");\n  const volEl = document.getElementById(\"tri-volume\");\n  const historyWrap = document.getElementById(\"tri-history-wrap\");\n  const historyList = document.getElementById(\"tri-history-list\");\n  function onFirstInteraction(e) {\n    removeUnlockListeners();\n    if (e.target === playBtn || playBtn.contains(e.target)) return;\n    if (!isPlaying) {\n      if (!userStopped) startStream(false, currentUrlIndex);\n    }\n  }\n  function addUnlockListeners() {\n    document.addEventListener(\"click\", onFirstInteraction);\n    document.addEventListener(\"keydown\", onFirstInteraction);\n  }\n  function removeUnlockListeners() {\n    document.removeEventListener(\"click\", onFirstInteraction);\n    document.removeEventListener(\"keydown\", onFirstInteraction);\n  }\n  function startStream(isAutoplay, idx) {\n    const urlIndex = typeof idx === \"number\" ? idx : 0;\n    const url = STREAM_CANDIDATES[urlIndex];\n    const myAttempt = ++playAttemptId;\n    statusEl.textContent = \"Connessione...\";\n    audio.pause();\n    audio.src = url;\n    audio.load();\n    audio.play().then(function() {\n      if (myAttempt !== playAttemptId || userStopped) return;\n      currentUrlIndex = urlIndex;\n      isPlaying = true;\n      removeUnlockListeners();\n      playBtn.textContent = \"\u25a0 STOP\";\n      statusEl.textContent = \"Riproduzione attiva\";\n    }).catch(function(err) {\n      if (myAttempt !== playAttemptId || userStopped) return;\n      if (err) {\n        if (err.name === \"NotAllowedError\") {\n          audio.removeAttribute(\"src\");\n          audio.load();\n          isPlaying = false;\n          playBtn.textContent = \"\u25b6 ASCOLTA\";\n          statusEl.textContent = \"Clicca sulla pagina o premi ASCOLTA\";\n          addUnlockListeners();\n          return;\n        }\n      }\n      if (STREAM_CANDIDATES[urlIndex + 1]) {\n        startStream(isAutoplay, urlIndex + 1);\n        return;\n      }\n      audio.removeAttribute(\"src\");\n      audio.load();\n      isPlaying = false;\n      playBtn.textContent = \"\u25b6 ASCOLTA\";\n      statusEl.textContent = \"Errore avvio stream\";\n    });\n  }\n  function stopStream() {\n    userStopped = true;\n    playAttemptId++;\n    removeUnlockListeners();\n    audio.pause();\n    audio.removeAttribute(\"src\");\n    audio.load();\n    isPlaying = false;\n    playBtn.textContent = \"\u25b6 ASCOLTA\";\n    statusEl.textContent = \"In pausa\";\n  }\n  function cleanFormat(rawFmt) {\n    let fmt = \"\";\n    if (typeof rawFmt === \"string\") {\n      fmt = rawFmt;\n    } else if (rawFmt) {\n      if (typeof rawFmt === \"object\") {\n        const vals = Object.values(rawFmt);\n        for (let i = 0; i !== vals.length; i++) {\n          if (typeof vals[i] === \"string\") {\n            fmt = vals[i];\n            break;\n          }\n        }\n      }\n    }\n    if (!fmt) return \"\";\n    const lower = fmt.toLowerCase();\n    if (lower.indexOf(\"aacp\") !== -1) return \"AAC+\";\n    if (lower.indexOf(\"aac\") !== -1) return \"AAC\";\n    if (lower.indexOf(\"mpeg\") !== -1 || lower.indexOf(\"mp3\") !== -1) return \"MP3\";\n    if (lower.indexOf(\"ogg\") !== -1) return \"OGG\";\n    const parts = fmt.split(\"\/\");\n    return parts[parts.length - 1].toUpperCase();\n  }\n  async function updateMetadata() {\n    try {\n      const res = await fetch(JSON_URL, { cache: \"no-store\" });\n      if (!res.ok) throw new Error(\"HTTP \" + res.status);\n      const data = await res.json();\n      if (data.status === false) {\n        badgeEl.textContent = \"OFFLINE\";\n        badgeEl.classList.add(\"is-offline\");\n      } else {\n        badgeEl.textContent = \"IN ONDA\";\n        badgeEl.classList.remove(\"is-offline\");\n      }\n      const infoParts = [];\n      if (data.bitrate) infoParts.push(data.bitrate + \" kbps\");\n      const fmtLabel = cleanFormat(data.format);\n      if (fmtLabel) infoParts.push(fmtLabel);\n      metaInfoEl.textContent = infoParts.join(\" \u2022 \");\n      let rawTrack = (data.nowplaying || \"\").trim();\n      if (rawTrack.toLowerCase().indexOf(\"now playing:\") === 0) {\n        rawTrack = rawTrack.slice(12).trim();\n      }\n      let title = \"Tele Radio Italia\";\n      let artist = \"In diretta\";\n      if (rawTrack) {\n        const sep = rawTrack.indexOf(\" - \");\n        if (sep !== -1) {\n          artist = rawTrack.slice(0, sep).trim();\n          title = rawTrack.slice(sep + 3).trim();\n        } else {\n          title = rawTrack;\n          artist = \"Tele Radio Italia\";\n        }\n      }\n      titleEl.textContent = title;\n      artistEl.textContent = artist;\n      const art = data.coverart || data.art || \"\";\n      if (art) {\n        coverEl.src = art;\n        coverEl.style.display = \"block\";\n      }\n      const hist = Array.isArray(data.history) ? data.history.slice(0, 5) : [];\n      if (hist.length) {\n        historyList.innerHTML = \"\";\n        hist.forEach(function(item) {\n          let text = \"\";\n          if (typeof item === \"string\") {\n            text = item;\n          } else if (item) {\n            text = item.title || item.track || \"\";\n          }\n          if (!text) return;\n          const li = document.createElement(\"li\");\n          li.className = \"tri-history-item\";\n          li.textContent = text;\n          historyList.appendChild(li);\n        });\n        if (historyList.children.length) historyWrap.style.display = \"block\";\n      }\n      if (\"mediaSession\" in navigator) {\n        navigator.mediaSession.metadata = new MediaMetadata({\n          title: title,\n          artist: artist,\n          album: \"Tele Radio Italia\",\n          artwork: art ? [{ src: art, sizes: \"512x512\", type: \"image\/jpeg\" }] : []\n        });\n      }\n    } catch (err) {\n      console.warn(\"Errore lettura metadati MediaCP:\", err);\n    }\n  }\n  playBtn.addEventListener(\"click\", function() {\n    if (isPlaying) {\n      stopStream();\n    } else {\n      userStopped = false;\n      removeUnlockListeners();\n      startStream(false, currentUrlIndex);\n    }\n  });\n  volEl.addEventListener(\"input\", function() {\n    audio.volume = parseFloat(volEl.value);\n  });\n  if (\"mediaSession\" in navigator) {\n    navigator.mediaSession.setActionHandler(\"play\", function() {\n      userStopped = false;\n      startStream(false, currentUrlIndex);\n    });\n    navigator.mediaSession.setActionHandler(\"pause\", stopStream);\n    navigator.mediaSession.setActionHandler(\"stop\", stopStream);\n  }\n  startStream(true, 0);\n  updateMetadata();\n  setInterval(updateMetadata, 15000);\n})();\n<\/script>\n","protected":false},"excerpt":{"rendered":"<p>IN ONDA Avvio&#8230; Tele Radio Italia In diretta \u25b6 ASCOLTA \ud83d\udd0a Ultimi brani trasmessi<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"open","template":"","meta":{"inspiro_hide_title":false,"inspiro_hide_featured_image":false,"footnotes":""},"class_list":["post-2","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/teleradioitalia.it\/index.php?rest_route=\/wp\/v2\/pages\/2","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/teleradioitalia.it\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/teleradioitalia.it\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/teleradioitalia.it\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/teleradioitalia.it\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2"}],"version-history":[{"count":10,"href":"https:\/\/teleradioitalia.it\/index.php?rest_route=\/wp\/v2\/pages\/2\/revisions"}],"predecessor-version":[{"id":31,"href":"https:\/\/teleradioitalia.it\/index.php?rest_route=\/wp\/v2\/pages\/2\/revisions\/31"}],"wp:attachment":[{"href":"https:\/\/teleradioitalia.it\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}