diff options
author | Joar Wandborg <git@wandborg.com> | 2012-03-27 12:05:09 +0200 |
---|---|---|
committer | Joar Wandborg <git@wandborg.com> | 2012-03-27 12:05:09 +0200 |
commit | deea3f6661df68a62d56317915ca1e71240061d4 (patch) | |
tree | 6b7708610db3500f07f494519d57eec7a0799eee /mediagoblin/static/js | |
parent | d0cb752992ce6cea2b8581dead5481591ddbb82b (diff) | |
parent | c56d4b55a169d67a3e5e5aba4271a67f0cb79c6f (diff) | |
download | mediagoblin-deea3f6661df68a62d56317915ca1e71240061d4.tar.lz mediagoblin-deea3f6661df68a62d56317915ca1e71240061d4.tar.xz mediagoblin-deea3f6661df68a62d56317915ca1e71240061d4.zip |
Merge remote-tracking branch 'joar/audio+sniffing'
Conflicts:
mediagoblin/media_types/image/processing.py
mediagoblin/media_types/video/__init__.py
mediagoblin/media_types/video/processing.py
mediagoblin/tests/test_submission.py
Diffstat (limited to 'mediagoblin/static/js')
-rw-r--r-- | mediagoblin/static/js/audio.js | 146 | ||||
-rw-r--r-- | mediagoblin/static/js/geolocation-map.js | 5 |
2 files changed, 151 insertions, 0 deletions
diff --git a/mediagoblin/static/js/audio.js b/mediagoblin/static/js/audio.js new file mode 100644 index 00000000..91d52f96 --- /dev/null +++ b/mediagoblin/static/js/audio.js @@ -0,0 +1,146 @@ +/** + * GNU MediaGoblin -- federated, autonomous media hosting + * Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +var audioPlayer = new Object(); + +(function (audioPlayer) { + audioPlayer.init = function (audioElement) { + audioPlayer.audioElement = audioElement; + console.log(audioElement); + attachEvents(); + $(audioElement).hide(); + }; + + function attachEvents () { + audioPlayer.audioElement.addEventListener('durationchange', audioPlayer.durationChange, true); + audioPlayer.audioElement.addEventListener('timeupdate', audioPlayer.timeUpdate, true); + audioPlayer.audioElement.addEventListener('progress', audioPlayer.onProgress, true); + $(document).ready( function () { + $('.audio-spectrogram').delegate('.seekbar', 'click', audioPlayer.onSeek); + $('.audio-spectrogram').delegate('.audio-control-play-pause', 'click', audioPlayer.playPause); + }); + } + + audioPlayer.onProgress = function(a, b, c) { + console.log(a, b, c); + buffered = audioPlayer.audioElement.buffered; + + ranges = new Array(); + + for (i = 0; i < buffered.length; i++) { + ranges[i] = new Array(); + ranges[i][0] = buffered.start(i); + ranges[i][1] = buffered.end(i); + } + console.log('ranges', ranges); + $('.audio-spectrogram .buffered').width( + (ranges[0][1] / audioPlayer.audioElement.duration) * audioPlayer.imageElement.width()); + }; + + audioPlayer.onSeek = function (e) { + console.log('onSeek', e); + im = audioPlayer.imageElement; + pos = e.offsetX / im.width(); + audioPlayer.audioElement.currentTime = pos * audioPlayer.audioElement.duration; + audioPlayer.audioElement.play(); + audioPlayer.setState(audioPlayer.PLAYING); + }; + + audioPlayer.playPause = function (e) { + console.log('playPause', e); + if (audioPlayer.audioElement.paused) { + audioPlayer.audioElement.play(); + audioPlayer.setState(audioPlayer.PLAYING); + } else { + audioPlayer.audioElement.pause(); + audioPlayer.setState(audioPlayer.PAUSED); + } + }; + + audioPlayer.NULL = null; + audioPlayer.PLAYING = 2; + audioPlayer.PAUSED = 4; + + audioPlayer.state = audioPlayer.NULL; + + audioPlayer.setState = function (state) { + if (state == audioPlayer.state) { + return; + } + + switch (state) { + case audioPlayer.PLAYING: + $('.audio-spectrogram .audio-control-play-pause') + .removeClass('paused').addClass('playing') + .text('■'); + break; + case audioPlayer.PAUSED: + $('.audio-spectrogram .audio-control-play-pause') + .removeClass('playing').addClass('paused') + .text('▶'); + break; + } + }; + + audioPlayer.durationChange = function () { + duration = audioPlayer.audioElement.duration; + }; + + audioPlayer.timeUpdate = function () { + currentTime = audioPlayer.audioElement.currentTime; + playhead = audioPlayer.imageElement.parent().find('.playhead'); + playhead.css('width', (currentTime / audioPlayer.audioElement.duration) * audioPlayer.imageElement.width()); + time = formatTime(currentTime); + duration = formatTime(audioPlayer.audioElement.duration); + audioPlayer.imageElement.parent().find('.audio-currentTime').text(time + '/' + duration); + }; + + function formatTime(seconds) { + var h = Math.floor(seconds / (60 * 60)); + var m = Math.floor((seconds - h * 60 * 60) / 60); + var s = Math.round(seconds - h * 60 * 60 - m * 60); + return '' + (h ? (h < 10 ? '0' + h : h) + ':' : '') + (m < 10 ? '0' + m : m) + ':' + (s < 10 ? '0' + s : s); + } + + audioPlayer.attachToImage = function (imageElement) { + /** + * Attach the player to an image element + */ + console.log(imageElement); + im = $(imageElement); + audioPlayer.imageElement = im; + $('<div class="playhead"></div>').appendTo(im.parent()); + $('<div class="buffered"></div>').appendTo(im.parent()); + $('<div class="seekbar"></div>').appendTo(im.parent()); + $('<div class="audio-control-play-pause paused">▶</div>').appendTo(im.parent()); + $('<div class="audio-currentTime">00:00</div>').appendTo(im.parent()); + }; +})(audioPlayer); + +$(document).ready(function () { + if (!$('.audio-media').length) { + return; + } + + console.log('Initializing audio player'); + + audioElements = $('.audio-media .audio-player'); + audioPlayer.init(audioElements[0]); + audioPlayer.attachToImage($('.audio-spectrogram img')[0]); +}); + diff --git a/mediagoblin/static/js/geolocation-map.js b/mediagoblin/static/js/geolocation-map.js index a2c62045..de49a37d 100644 --- a/mediagoblin/static/js/geolocation-map.js +++ b/mediagoblin/static/js/geolocation-map.js @@ -17,6 +17,11 @@ */ $(document).ready(function () { + if (!$('#tile-map').length) { + return; + } + console.log('Initializing map'); + var longitude = Number( $('#tile-map #gps-longitude').val()); var latitude = Number( |