UNPKG

@speechkit/speechkit-audio-player

Version:

A web player component that can play audio from https://speechkit.io

172 lines (165 loc) 5.69 kB
function getParameterByName(name, url) { if (!url) url = window.location.href; name = name.replace(/[\[\]]/g, "\\$&"); var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), results = regex.exec(url); if (!results) return null; if (!results[2]) return ""; return decodeURIComponent(results[2].replace(/\+/g, " ")); } var podcast = { id: "3a6e0e3e-faaa-4080-89e9-eaebd5ce9f2a", podcast_id: 96609, url: "", title: "July test", author: "", summary: "", image: null, published_at: "2018-07-18T05:01:11.532Z", body: "Google Doodler Katy Wu tells us a little bit about the creative process behind making the Nelson Mandela doodle.\nGetting to celebrate someone as monumental and influential as Nelson Mandela must have been exciting, but also kind of intimidating. Can you tell me a little about your experience working on this project?\nA few months ago I was looking to work on a bigger project and the time was right, so I got assigned to work on the Mandela doodle. At first I thought I would have to make a very serious, somber sort of doodle and I wasn’t sure what to do.\n", state: "processed", share_url: "http://spkt.local:3000/a/96609", share_version: "v2", media: [ { id: 216800, role: "body", content_type: "application/x-mpegURL", url: "https://d22tbkdovk5ea2.cloudfront.net/audio/projects/558/podcasts/86361/roles/body/voices/94/14a80ee640fb845f92d0552d21175b4c.m3u8", created_at: "2018-05-09T12:54:11.307Z", updated_at: "2018-05-09T12:54:20.229Z", state: "processed", duration: 303.258671 }, { id: 216799, role: "body", content_type: "audio/mpeg", url: "https://d22tbkdovk5ea2.cloudfront.net/audio/projects/558/podcasts/86361/roles/body/voices/94/bb93859588414ef3db004bb5ed37146a.mp3", created_at: "2018-05-09T12:54:02.014Z", updated_at: "2018-05-09T12:54:10.809Z", state: "processed", duration: 303.216 } ], player_type: "MinimalPlayer", next_podcast_external_id: "8fea639c-9b11-4bc7-acda-adc834fe72f1" }; var podcast2 = { id: "8f988fb3-3dc7-4c73-bb9e-0e1654822ce1", podcast_id: 91730, url: "", title: "Stand by me:", author: "", summary: "", image: null, published_at: "2018-06-21T13:04:16.683Z", body: "ou ou oh staaan by me:", state: "processed", share_url: "http://spkt.local:3000/a/91730", share_version: "v2", media: [ { id: 216800, role: "body", content_type: "application/x-mpegURL", url: "https://d22tbkdovk5ea2.cloudfront.net/audio/projects/558/podcasts/86361/roles/body/voices/94/14a80ee640fb845f92d0552d21175b4c.m3u8", created_at: "2018-05-09T12:54:11.307Z", updated_at: "2018-05-09T12:54:20.229Z", state: "processed", duration: 303.258671 }, { id: 216799, role: "body", content_type: "audio/mpeg", url: "https://d22tbkdovk5ea2.cloudfront.net/audio/projects/558/podcasts/86361/roles/body/voices/94/bb93859588414ef3db004bb5ed37146a.mp3", created_at: "2018-05-09T12:54:02.014Z", updated_at: "2018-05-09T12:54:10.809Z", state: "processed", duration: 303.216 } ], player_type: "MinimalPlayer", next_podcast_external_id: "3a6e0e3e-faaa-4080-89e9-eaebd5ce9f2a" }; var podcast3 = { id: "a42f0def-9b54-43cf-9281-d5a070ff8e86", podcast_id: 91454, url: "", title: "test", author: "", summary: "", image: null, published_at: "2018-06-20T10:56:13.227Z", body: "aaa", state: "processed", share_url: "http://spkt.local:3000/a/91454", share_version: "v2", media: [ { id: 216800, role: "body", content_type: "application/x-mpegURL", url: "https://d22tbkdovk5ea2.cloudfront.net/audio/projects/558/podcasts/86361/roles/body/voices/94/14a80ee640fb845f92d0552d21175b4c.m3u8", created_at: "2018-05-09T12:54:11.307Z", updated_at: "2018-05-09T12:54:20.229Z", state: "processed", duration: 303.258671 }, { id: 216799, role: "body", content_type: "audio/mpeg", url: "https://d22tbkdovk5ea2.cloudfront.net/audio/projects/558/podcasts/86361/roles/body/voices/94/bb93859588414ef3db004bb5ed37146a.mp3", created_at: "2018-05-09T12:54:02.014Z", updated_at: "2018-05-09T12:54:10.809Z", state: "processed", duration: 303.216 } ], player_type: "MinimalPlayer", next_podcast_external_id: "7550d000-c554-421a-9652-3d67a63b3e1a" }; var articleUrl = getParameterByName("articleUrl"); var player = getParameterByName("ampPlayer") || "EmbeddedPlayer" || getParameterByName("player") || "EmbeddedPlayer"; var isAmp = !!getParameterByName("isAmp"); // Resolve articleurl if no podcast and if not passed if (!podcast && !articleUrl) { articleUrl = document.referrer; if (document.referrer.indexOf("https://m.nettavisen.no") !== -1) { articleUrl = document.referrer.replace("https://m.", "https://www."); } if (document.referrer.indexOf("http://testm.standaard.be") !== -1) { articleUrl = document.referrer.replace("http://testm", "http://test"); } } var options = { skBackend: "http://spkt.local:3000", renderNode: "render-here", apiKey: "read_af356f33a0df6b30f7bb219e635e3b26", projectId: "607", projectCampaignId: "18", podcastUrl: "https://www.bbc.co.uk/news/world-middle-east-45726750", publisherId: "403", publisher: "BBC Rss", publisherLogo: "", publisherColor: "#6653ff", language: "en_GB", podcasts: [podcast, podcast2, podcast3], articleUrl: articleUrl, feedbackUrl: "http://spkt.local:3000/rate/basic", message: "", isAmp: isAmp };