UNPKG

@speechkit/speechkit-audio-player

Version:

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

162 lines (146 loc) 8.7 kB
(function(sk) { // use strict mode to help prevent errors 'use strict'; // //subscribe to events // _eventSubscribe = function(fn, eventName) { // window.addEventListener(eventName, function(event){ // fn(event); // }); // }, var id = 'a',callback='b'; var sPlayerUrl = './speechkit-player.js'; console.log(speechkit,id, callback,'id'); var createPlayer = (SpeechKit) => { var podcast = {"id":"8a83f93d-bbcc-4eab-8676-003daff1156b","podcast_id":278859,"url":"http://test.com","title":"one more test title ","author":"author","summary":"one more test body... ","image":null,"published_at":"2020-03-06T13:30:44.487Z","body":"one more test body ","state":"processed","share_url":"https://staging.spkt.io/a/278859","share_version":"v2","media":[{"id":2210502,"role":"body","content_type":"application/x-mpegURL","url":"https://speechkit-staging.s3.amazonaws.com/audio/projects/2603/podcasts/278859/media/a8ca5e8429ca54b742f4c147b1a9cf6e.m3u8","download_url":null,"created_at":"2020-03-06T13:30:46.839Z","updated_at":"2020-03-06T13:30:47.168Z","state":"processed","duration":3.548622,"voice":{"id":307,"language":"en_US","name":"Joanna"}},{"id":2210500,"role":"body","content_type":"audio/mpeg","url":"https://speechkit-staging.s3.amazonaws.com/audio/projects/2603/podcasts/278859/media/0229aaf32220669f58dacd9848ddd822_compiled.mp3","download_url":null,"created_at":"2020-03-06T13:30:46.521Z","updated_at":"2020-03-06T13:30:46.608Z","state":"processed","duration":3.576,"voice":{"id":307,"language":"en_US","name":"Joanna"}}],"player_type":"EmbeddedPlayer","next_podcast_external_id":null,"ad_disabled":false}; var player = 'MinimalPlayer'; var campaignId = 195; var oPlayerData = { player: player, skBackend: "https://staging.spkt.io", renderNode: id, apiKey: "read_33dbe2628d957eefe4a73b57c95c3e27", projectId: "2603", customAdMedia: null, projectCampaignId: campaignId, podcastUrl: "http://test.com", publisherId: "1085", publisher: "Speechkit Landing Page (DO NOT DELETE!)", publisherLogo: "", publisherColor: "#000", language: "en_US", podcast: podcast, articleUrl: window.location.href, feedbackUrl: "https://staging.spkt.io/rate/basic", } // Run SK return new SpeechKit.players(oPlayerData); }, // This promise will be used by Promise.all to determine success or failure setupPlayer = function(callback) { return new Promise(function(resolve, reject) { var player; var element = document.body, spktScript = document.createElement('script'); // add the script to the page spktScript.src = sPlayerUrl; element.appendChild(spktScript); // on load of script spktScript.onload = function() { if(!window.SpeechKit) { console.log('error logging here'); reject(); } createPlayer(window.SpeechKit) .then(currentPlayer => { currentPlayer.load(); currentPlayer.on('ready', function() { resolve(); }) currentPlayer.on('didPlay', function() { console.log( 'PLAY'); }) currentPlayer.on('didProgress', function() { console.log( 'DID PROJGREES'); }) currentPlayer.on('play', function() { console.log( 'PLAYasass'); }) // debugger; }); //subscribe to all the events which the player already tried to subscribe to before admanager is loaded // for(var i=0; i<COULL.jammaster.aSubscribedEvents.length; i++) { // var eventFunction = COULL.jammaster.aSubscribedEvents[i].fn, // eventName = COULL.jammaster.aSubscribedEvents[i].eventName; // // Add functionality to following event subscriptions as callback so our code runs before the player's code // if(eventName ==='AdError' || eventName==='AdImpression'|| eventName==='AdStopped') { // eventFunction = getCombinedFunction(eventName, eventFunction); // } // //subscribe to vpaid events required to send any stored coull tracking urls // _admanProxyObj.subscribe(eventFunction, eventName); // } // if(_admanProxyObj.initAd) { // // initialise the ad manager using the parameters we saved in the coull proxy object // _admanProxyObj.initAd(COULL.oInitAdParams.width, COULL.oInitAdParams.height, COULL.oInitAdParams.viewMode, COULL.oInitAdParams.desiredBitrate, COULL.oInitAdParams.creativeData, COULL.oInitAdParams.environmentVars, COULL.oInitAdParams.adType); // // COULL.tracking.loadMoat('preroll'); disabled as no longer running moat/preroll test -TR // } else { // errorCallback(700); // Ad Manager Error // } }; }); }, // //unsubscribe to event (log no args) // _eventUnsubscribe = function(fn, eventName) { // if(!window){ // return false; // } // window.removeEventListener(eventName, fn); // }, // create all custom events (log no args) createEvents = () => { // array of custom events we need to create var aEvents = ['AdError','AdStarted','AdUserClose','AdPaused','AdPlaying','AdStopped','AdSizeChange','AdImpression','AdLoaded']; // create all events in above array // COULL.utils.createCustomEvents(aEvents); }, a = (a,b,c) => { console.log(a,b,c, 'a'); }; // setupPlayer().then(callback); //public properties & functions to return (preceded by underscore '_') return { a : a }; })(window.sk ); //! End of Overlay Module // (function() { // // SDK LISTENER CODE: // window.document.addEventListener('playerJsReciever', handleEvent, false); // function handleEvent(e) { // console.log(e.detail); // outputs: object // } // var podcast = {"id":"8a83f93d-bbcc-4eab-8676-003daff1156b","podcast_id":278859,"url":"http://test.com","title":"one more test title ","author":"author","summary":"one more test body... ","image":null,"published_at":"2020-03-06T13:30:44.487Z","body":"one more test body ","state":"processed","share_url":"https://staging.spkt.io/a/278859","share_version":"v2","media":[{"id":2210502,"role":"body","content_type":"application/x-mpegURL","url":"https://speechkit-staging.s3.amazonaws.com/audio/projects/2603/podcasts/278859/media/a8ca5e8429ca54b742f4c147b1a9cf6e.m3u8","download_url":null,"created_at":"2020-03-06T13:30:46.839Z","updated_at":"2020-03-06T13:30:47.168Z","state":"processed","duration":3.548622,"voice":{"id":307,"language":"en_US","name":"Joanna"}},{"id":2210500,"role":"body","content_type":"audio/mpeg","url":"https://speechkit-staging.s3.amazonaws.com/audio/projects/2603/podcasts/278859/media/0229aaf32220669f58dacd9848ddd822_compiled.mp3","download_url":null,"created_at":"2020-03-06T13:30:46.521Z","updated_at":"2020-03-06T13:30:46.608Z","state":"processed","duration":3.576,"voice":{"id":307,"language":"en_US","name":"Joanna"}}],"player_type":"EmbeddedPlayer","next_podcast_external_id":null,"ad_disabled":false}; // var player = 'MinimalPlayer'; // var campaignId = 195; // // Run SK // new SpeechKit.players({ // player: player, // skBackend: "https://staging.spkt.io", // renderNode: 'speechkit-player', // apiKey: "read_33dbe2628d957eefe4a73b57c95c3e27", // projectId: "2603", // customAdMedia: null, // projectCampaignId: campaignId, // podcastUrl: "http://test.com", // publisherId: "1085", // publisher: "Speechkit Landing Page (DO NOT DELETE!)", // publisherLogo: "", // publisherColor: "#000", // language: "en_US", // podcast: podcast, // articleUrl: window.location.href, // feedbackUrl: "https://staging.spkt.io/rate/basic", // }).then(function(currentPlayer) { // console.log(currentPlayer); // currentPlayer.load(); // }); // })()