Дополнение воспроизведения звуковых файлов для Google-таблиц
08.10.2018 16:30
0Плагин открывается в сайдбаре и при щелчке на ячейку с URL пытается проиграть данный файл в HTML5-встроенном плеере, есть возможность управлять текущим воспроизведением.
Исходный код плагина (можно просто вставить в редактор скриптов любого листа Google-таблиц):
function onOpen( e ){ var ui = SpreadsheetApp.getUi(); ui.createAddonMenu() .addItem( "Soundbar", "soundbar" ) .addToUi(); }; function onInstall( e ){ onOpen( e ); }; function getRecord() { var sheet = SpreadsheetApp.getActiveSheet(); var cellval = sheet.getCurrentCell().getValue(); return cellval; } function soundbar() { var html = '<html><head><base target="_top"></head><body>' + '<div class="sidebar">' + '<audio id="soundbarPlayer" controls="controls" disabled="disabled" volume="0.5">' + '<source id="soundbarPlayerSource" src="" />' + 'Your browser does not support the audio element.' + '</audio><br />' + '<div id="soundbarStatus">loading...</div>' + '<script>' + 'function status( msg ) { document.getElementById("soundbarStatus" ).innerHTML = msg; }' + 'function show( data, error ) {' + 'if ( !data ) data = null;' + 'if ( ( data && !error &&!/^\s*(?:http|https|ftp):/i.test( data ) ) || ( !data && !error ) ) {error = "[" + data + "] is not a url"; data = null; }' + 'if ( error ) status( "error: " + error );' + 'else status( "playing: " + data );' + 'var p = document.getElementById( "soundbarPlayer" );' + 'var s = document.getElementById( "soundbarPlayerSource" );' + 'if ( s.src === data ) return;' + 'p.pause();' + 'p.currentTime = 0;' + 's.src = "";' + 'p.disabled = true;' + 'if ( data ) {' + 'p.disabled = false;' + 's.src = data;' + 'p.load();' + 'p.play();' + '}' + '}' + 'function poll( t ) {' + 'setTimeout(' + 'function() {' + 'pollHandler();' + '},' + 't || 1000' + ');' + '}' + 'function pollHandler() {' + 'if ( !window.google || !window.google.script ||!window.google.script.run || !window.google.script.run.getRecord ) {poll(); return; }' + 'google.script.run' + '.withSuccessHandler( function( data ) { show( data ); poll(); } )' + '.withFailureHandler( function( msg, el ) { show( null, msg );poll(); } )' + '.getRecord();' + '}' + 'window.onload = function() {' + 'status( "ready..." );' + 'pollHandler();' + '};' + '</script>' '</div>' + '</body></html>'; var ui = HtmlService.createHtmlOutput( html ) .setSandboxMode( HtmlService.SandboxMode.IFRAME ) .setTitle( "Soundbar" ); SpreadsheetApp.getUi().showSidebar( ui ); }
Чтобы его включить этот сайдбар, в главном меню Google-таблиц зайти в Add-ons > Sound > Soundbar.
Плагин опубликован в Google и в данный момент проходит проверку, после чего станет доступен в официальной коллекции дополнений, я добавлю его ссылку из гугл-стор сюда.

08.10.2018, Protocoder