diff --git a/platypush/backend/http/static/css/video.omxplayer.css b/platypush/backend/http/static/css/video.omxplayer.css index 4c8d6efd0..c0cff1dfb 100644 --- a/platypush/backend/http/static/css/video.omxplayer.css +++ b/platypush/backend/http/static/css/video.omxplayer.css @@ -1,6 +1,6 @@ #video-search { max-width: 60em; - margin: 3em auto 1em auto; + margin: 1em auto; } #video-search input[type=text] { @@ -11,3 +11,64 @@ form#video-ctrl { text-align: center; } +#video-seeker-container { + margin-top: 0.5em; + margin-bottom: 1em; +} + +#video-volume-ctrl-container { + margin-top: 1em; +} + +#video-results { + padding: 1.5rem 1.5rem 0 .5rem; + background: #f8f8f8; +} + + .video-result { + padding: 5px; + letter-spacing: .1rem; + line-height: 3.3rem; + cursor: pointer; + } + + .video-result.selected { + background-color: #c8ffd0 !important; + } + + .video-result:hover { + background-color: #daf8e2 !important; + } + + .video-result:nth-child(odd) { + background-color: #f2f2f2; + } + + .video-result.active { + height: 4rem; + padding-top: 1.5rem; + font-size: 1.7rem; + border-radius: 10px; + animation: active-track 5s; + -moz-animation: active-track 5s infinite; + -webkit-animation: active-track 5s infinite; + } + + @keyframes active-track { + 0% { background: #d4ffe3; } + 50% { background: #9cdfb0; } + 100% { background: #d4ffe3; } + } + + @-moz-keyframes active-track { + 0% { background: #d4ffe3; } + 50% { background: #9cdfb0; } + 100% { background: #d4ffe3; } + } + + @-webkit-keyframes active-track { + 0% { background: #d4ffe3; } + 50% { background: #9cdfb0; } + 100% { background: #d4ffe3; } + } + diff --git a/platypush/backend/http/static/js/music.mpd.js b/platypush/backend/http/static/js/music.mpd.js index 7613e7169..70f94d3d7 100644 --- a/platypush/backend/http/static/js/music.mpd.js +++ b/platypush/backend/http/static/js/music.mpd.js @@ -521,26 +521,11 @@ $(document).ready(function() { ); }); - $volumeCtrl.on('mousedown', function(event) { + $volumeCtrl.on('mousedown touchstart', function(event) { prevVolume = $(this).val(); }); - $volumeCtrl.on('mouseup', function(event) { - execute( - { - type: 'request', - action: 'music.mpd.setvol', - args: { vol: $(this).val() } - }, - - onSuccess=undefined, - onError = function() { - $volumeCtrl.val(prevVolume); - } - ); - }); - - $volumeCtrl.on('mouseup', function(event) { + $volumeCtrl.on('mouseup touchend', function(event) { execute( { type: 'request', diff --git a/platypush/backend/http/static/js/video.omxplayer.js b/platypush/backend/http/static/js/video.omxplayer.js index dd7c9e8c7..d19465fd7 100644 --- a/platypush/backend/http/static/js/video.omxplayer.js +++ b/platypush/backend/http/static/js/video.omxplayer.js @@ -1,41 +1,66 @@ $(document).ready(function() { var $container = $('#video-container'), $searchForm = $('#video-search'), - $ctrlForm = $('#video-ctrl'); + $videoResults = $('#video-results'), + $volumeCtrl = $('#video-volume-ctrl'), + $ctrlForm = $('#video-ctrl'), + prevVolume = undefined; + + var updateVideoResults = function(videos) { + $videoResults.html(''); + for (var video of videos) { + var $videoResult = $('
') + .addClass('video-result') + .attr('data-url', video['url']) + .html('title' in video ? video['title'] : video['url']); + + $videoResult.appendTo($videoResults); + } + }; var initBindings = function() { $searchForm.on('submit', function(event) { - var formData = $(this).serializeArray().reduce(function(obj, item) { - var value = item.value.trim(); - if (value.length > 0) { - obj[item.name] = item.value; - } + var $input = $(this).find('input[name=video-search-text]'); + var resource = $input.val(); + var request = {} + var onSuccess = function() {}; + var onError = function() {}; + var onComplete = function() { + $input.prop('disabled', false); + }; - return obj; - }, {}); + $input.prop('disabled', true); + $videoResults.text('Searching...'); - execute( - { + if (resource.match(new RegExp('^https?://')) || + resource.match(new RegExp('^file://'))) { + var videos = [{ url: resource }]; + updateVideoResults(videos); + + request = { type: 'request', - action: 'video.omxplayer.stop', - }, + action: 'video.omxplayer.play', + args: { resource: resource } + }; + } else { + request = { + type: 'request', + action: 'video.omxplayer.youtube_search', + args: { query: resource } + }; - function() { - execute( - { - type: 'request', - action: 'video.omxplayer.play', - args: formData, - } - ) - } - ); + onSuccess = function(response) { + var videos = response.response.output; + updateVideoResults(videos); + }; + } + execute(request, onSuccess, onError, onComplete) return false; }); $ctrlForm.on('submit', function() { return false; }); - $ctrlForm.find('button[data-action]').on('click', function(evt) { + $ctrlForm.find('button[data-action]').on('click touch', function(evt) { var action = $(this).data('action'); var $btn = $(this); @@ -46,6 +71,54 @@ $(document).ready(function() { } ); }); + + $volumeCtrl.on('mousedown touchstart', function(event) { + prevVolume = $(this).val(); + }); + + $volumeCtrl.on('mouseup touchend', function(event) { + execute( + { + type: 'request', + action: 'video.omxplayer.set_volume', + args: { volume: $(this).val() } + }, + + onSuccess=undefined, + onError = function() { + $volumeCtrl.val(prevVolume); + } + ); + }); + + $videoResults.on('click touch', '.video-result', function(evt) { + var results = $videoResults.html(); + var $item = $(this); + if (!$item.hasClass('selected')) { + $item.siblings().removeClass('selected'); + $item.addClass('selected'); + return false; + } + + $videoResults.text('Loading video...'); + execute( + { + type: 'request', + action: 'video.omxplayer.play', + args: { resource: $item.data('url') }, + }, + + function() { + $videoResults.html(results); + $item.siblings().removeClass('active'); + $item.addClass('active'); + }, + + function() { + $videoResults.html(results); + }, + ); + }); }; var init = function() { diff --git a/platypush/backend/http/templates/plugins/video.omxplayer.html b/platypush/backend/http/templates/plugins/video.omxplayer.html index 3d4ec3aac..e541972c7 100644 --- a/platypush/backend/http/templates/plugins/video.omxplayer.html +++ b/platypush/backend/http/templates/plugins/video.omxplayer.html @@ -4,14 +4,14 @@