Changed soundmanager to not prefer flash

This commit is contained in:
Fergal Moran
2014-05-14 22:10:58 +01:00
parent c7eb1b814e
commit 98272ee0e5
13 changed files with 86 additions and 469 deletions

View File

@@ -100,7 +100,7 @@ TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS + (
'django.contrib.auth.context_processors.auth', 'django.contrib.auth.context_processors.auth',
"allauth.socialaccount.context_processors.socialaccount", "allauth.socialaccount.context_processors.socialaccount",
"allauth.account.context_processors.account", "allauth.account.context_processors.account",
"spa.context_processors.debug" "spa.context_processors.dss_context"
) )
AUTHENTICATION_BACKENDS = global_settings.AUTHENTICATION_BACKENDS + ( AUTHENTICATION_BACKENDS = global_settings.AUTHENTICATION_BACKENDS + (

View File

@@ -1,5 +1,8 @@
from django.conf import settings from django.conf import settings
def debug(context): def dss_context(context):
return {'DEBUG': settings.DEBUG} return {
'DEBUG': settings.DEBUG,
'live_enabled': settings.LIVE_ENABLED
}

View File

@@ -15,10 +15,11 @@ define ['app', 'marionette', 'vent', 'utils', 'soundmanager2', 'peneloplay'],
soundManager.setup soundManager.setup
url: com.podnoms.settings.staticUrl + '/swf/sm/' url: com.podnoms.settings.staticUrl + '/swf/sm/'
onready: -> onready: ->
console.log "Sound manager ready sir!" vent.trigger('peneloplay:ready')
console.log "Sound manager ready!"
debugFlash: com.podnoms.smDebugMode debugFlash: com.podnoms.smDebugMode
preferFlash: true preferFlash: false
defaultOptions: defaultOptions:
volume: com.podnoms.settings.volume volume: com.podnoms.settings.volume

View File

@@ -27,10 +27,11 @@
return soundManager.setup({ return soundManager.setup({
url: com.podnoms.settings.staticUrl + '/swf/sm/', url: com.podnoms.settings.staticUrl + '/swf/sm/',
onready: function() { onready: function() {
return console.log("Sound manager ready sir!"); vent.trigger('peneloplay:ready');
return console.log("Sound manager ready!");
}, },
debugFlash: com.podnoms.smDebugMode, debugFlash: com.podnoms.smDebugMode,
preferFlash: true, preferFlash: false,
defaultOptions: { defaultOptions: {
volume: com.podnoms.settings.volume volume: com.podnoms.settings.volume
} }

View File

@@ -3,7 +3,7 @@ define ['jquery', 'utils', 'facebook'], ($, utils) ->
#first off, find if the current user has allowed facebook likes #first off, find if the current user has allowed facebook likes
$.getJSON "social/like/" + mixId + "/", (data) -> $.getJSON "social/like/" + mixId + "/", (data) ->
com.podnoms.utils.showAlert "Posted your like to facebook, you can stop this in your settings page.", "Cheers feen" utils.showAlert "Posted your like to facebook, you can stop this in your settings page.", "Cheers feen"
generateEmbedCode: (model) -> generateEmbedCode: (model) ->

View File

@@ -5,7 +5,7 @@
return { return {
postFacebookLike: function(mixId) { postFacebookLike: function(mixId) {
return $.getJSON("social/like/" + mixId + "/", function(data) { return $.getJSON("social/like/" + mixId + "/", function(data) {
return com.podnoms.utils.showAlert("Posted your like to facebook, you can stop this in your settings page.", "Cheers feen"); return utils.showAlert("Posted your like to facebook, you can stop this in your settings page.", "Cheers feen");
}); });
}, },
generateEmbedCode: function(model) { generateEmbedCode: function(model) {

View File

@@ -41,7 +41,7 @@ define ['jquery', 'lib/jquery.filedownload', 'bootstrap', 'toastr'],
checkPlayCount: -> checkPlayCount: ->
if document.cookie.indexOf("sessionId") if document.cookie.indexOf("sessionId")
$.getJSON "/ajax/session_play_count", (data) => $.getJSON "/ajax/session_play_count/", (data) =>
console.log "utils: got playcount" console.log "utils: got playcount"
if data.play_count isnt "0" and ((data.play_count % com.podnoms.settings.nag_count) == 0) if data.play_count isnt "0" and ((data.play_count % com.podnoms.settings.nag_count) == 0)
@modal "/dlg/PlayCountLoginAlert" @modal "/dlg/PlayCountLoginAlert"

View File

@@ -55,7 +55,7 @@
checkPlayCount: function() { checkPlayCount: function() {
var _this = this; var _this = this;
if (document.cookie.indexOf("sessionId")) { if (document.cookie.indexOf("sessionId")) {
$.getJSON("/ajax/session_play_count", function(data) { $.getJSON("/ajax/session_play_count/", function(data) {
console.log("utils: got playcount"); console.log("utils: got playcount");
if (data.play_count !== "0" && ((data.play_count % com.podnoms.settings.nag_count) === 0)) { if (data.play_count !== "0" && ((data.play_count % com.podnoms.settings.nag_count) === 0)) {
return _this.modal("/dlg/PlayCountLoginAlert"); return _this.modal("/dlg/PlayCountLoginAlert");

View File

@@ -0,0 +1,54 @@
// Generated by CoffeeScript 1.4.0
(function() {
var __hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
define(['app', 'vent', 'marionette', 'fullcalendar', 'models/show/showCollection', 'models/mix/mixCollection', 'text!/tpl/ShowScheduleMixItem'], function(App, vent, Marionette, fullcalendar, ScheduleCollection, MixCollection, Template) {
var ScheduleShowMixItem, ScheduleShowMixList;
ScheduleShowMixItem = (function(_super) {
__extends(ScheduleShowMixItem, _super);
function ScheduleShowMixItem() {
return ScheduleShowMixItem.__super__.constructor.apply(this, arguments);
}
ScheduleShowMixItem.prototype.template = _.template(Template);
return ScheduleShowMixItem;
})(Marionette.ItemView);
ScheduleShowMixList = (function(_super) {
__extends(ScheduleShowMixList, _super);
function ScheduleShowMixList() {
return ScheduleShowMixList.__super__.constructor.apply(this, arguments);
}
ScheduleShowMixList.prototype.itemView = ScheduleShowMixItem;
ScheduleShowMixList.prototype.initialize = function(options) {
console.log("ScheduleShowMixList: initialize");
return true;
};
ScheduleShowMixList.prototype.onShow = function() {
return $("#external-events div.external-event").each(function() {
$(this).draggable({
zIndex: 999,
revert: true,
revertDuration: 0
});
});
};
true;
return ScheduleShowMixList;
})(Marionette.CollectionView);
return ScheduleShowMixList;
});
}).call(this);

View File

@@ -1,268 +0,0 @@
/** @license
----------------------------------------------
Copyright (c) 2012, Fergal Moran. All rights reserved.
Code provided under the BSD License:
*/
if (!com) var com = {};
if (!com.podnoms) com.podnoms = {};
soundManager.url = com.podnoms.settings.staticUrl + '/swf/sm/';
soundManager.bgColor = '#ffffff';
soundManager.consoleOnly = true;
soundManager.debugMode = com.podnoms.settings.smDebugMode;
soundManager.debugFlash = com.podnoms.settings.smDebugMode;
soundManager.flashVersion = 9;
soundManager.flashPollingInterval = null;
soundManager.html5PollingInterval = null;
soundManager.html5Test = /^(probably|maybe)$/i;
soundManager.flashLoadTimeout = 1000;
soundManager.idPrefix = 'sound';
soundManager.noSWFCache = false;
soundManager.preferFlash = false;
soundManager.useConsole = true;
soundManager.useFlashBlock = false;
soundManager.useHighPerformance = false;
soundManager.useHTML5Audio = true;
soundManager.waitForWindowLoad = false;
soundManager.wmode = null;
com.podnoms.player = {
/*Members*/
currentId: -1,
currentPath: '',
currentSound: null,
boundingEl: null,
timeDisplayLabel: null,
waveFormEl: null,
playHeadEl: null,
loadingEl: null,
seekHeadEl: null,
waveFormRect: [-1, -1, -1, -1],
trackLoaded: false,
waveFormTop: -1,
waveFormLeft: -1,
waveFormWidth: -1,
totalLength: -1,
currentPosition: -1,
soundDuration: 0,
/*Privates */
_secondsToHms: function (d) {
if (d) {
d = Number(d);
var h = Math.floor(d / 3600);
var m = Math.floor(d % 3600 / 60);
var s = Math.floor(d % 3600 % 60);
return ((h > 0 ? h + ":" : "") + (m > 0 ? (h > 0 && m < 10 ? "0" : "") + m + ":" : "00:") + (s < 10 ? "0" : "") + s);
} else {
return "00:00:00";
}
},
_getDurationEstimate: function (oSound) {
if (oSound.instanceOptions.isMovieStar) {
return (oSound.duration);
} else {
return oSound.durationEstimate;
}
},
_whileLoading: function () {
var percentageFinished = (this.currentSound.bytesLoaded / this.currentSound.bytesTotal) * 100;
var percentageWidth = (this.waveFormWidth / 100) * percentageFinished;
this.loadingEl.css('width', percentageWidth);
},
_whilePlaying: function () {
if (!this.trackLoaded) {
this.trackLoaded = true;
this.loadingEl.css('width', 100);
}
//need to call this every time as the boundaries may have changed.
this._calculateBounds();
this.currentPosition = this.currentSound.position;
var duration = this._getDurationEstimate(this.currentSound);
var percentageFinished = (this.currentSound.position / duration) * 100;
var percentageWidth = (this.waveFormWidth / 100) * percentageFinished;
this.playHeadEl.css('width', percentageWidth);
this.timeDisplayLabel.text(this._secondsToHms(this.currentSound.position / 1000));
},
_mouseDown: function (event) {
if (this.currentSound != null) {
this.currentSound.setPosition(
(this._getDurationEstimate(this.currentSound) / 100) * ((event.pageX - this.waveFormLeft) / this.waveFormWidth) * 100);
}
$(event.currentTarget).mouseup($.proxy(this._mouseDown, this));
},
_mouseMove: function (event) {
this.seekHeadEl.css('left', (event.pageX - this.waveFormLeft));//.fadeIn('fast');
},
_mouseLeave: function (event) {
this.seekHeadEl.hide();
},
_mouseEnter: function (event) {
this.seekHeadEl.show();
},
_destroyCurrent: function (success) {
if (this.currentSound != null) {
soundManager.destroySound(this.currentSound.sID);
}
this.trackLoaded = false;
this.currentId = null;
if (success != undefined)
success();
},
_parseOptions: function (options) {
this.currentId = options.id;
this.boundingEl = options.boundingEl;
this.waveFormEl = options.waveFormEl;
this.seekHeadEl = options.seekHeadEl;
this.playHeadEl = options.playHeadEl;
this.loadingEl = options.loadingEl;
this.currentPath = options.url;
},
_calculateBounds: function () {
if (this.waveFormEl.position()) {
this.waveFormTop = this.waveFormEl.position().top;
this.waveFormLeft = this.waveFormEl.offset().left;
this.waveFormWidth = this.waveFormEl.width();
this.playHeadEl.css('top', 0);
this.loadingEl.css('top', 0);
this.seekHeadEl.css('top', this.waveFormEl.position().top);
/*this.waveFormEl.mousedown($.proxy(this._mouseDown, this));*/
this.waveFormEl.mouseup($.proxy(this._mouseDown, this));
this.waveFormEl.mousemove($.proxy(this._mouseMove, this));
this.waveFormEl.mouseout($.proxy(this._mouseLeave, this));
this.waveFormEl.mouseenter($.proxy(this._mouseEnter, this));
} else {
console.error("Error setting up player, waveFormEl is empty");
}
},
/*Methods*/
isPlaying: function () {
if (this.currentSound != null)
return this.currentSound.playState == 1;
},
isPlayingId: function (id) {
return this.isPlaying() && this.currentSound.sID == "com.podnoms.player-" + id;
},
getStreamUrl: function () {
return this.currentPath;
},
drawTimeline: function (el, boundingEl, duration) {
/*
Assume 10 markers
*/
var markerDuration = duration / 10;
var item = $(document.createElement("li"));
for (var i = 0; i < 10; i++) {
var sliceDuration = moment.duration(markerDuration * (i + 1), "seconds");
var text = sliceDuration.hours() != 0 ?
moment(sliceDuration).format("HH:mm") :
moment(sliceDuration).format("mm:ss");
el.append(item.clone().text(text).css('width', '10%'));
}
},
setupPlayer: function (options) {
this._parseOptions(options);
this._calculateBounds();
this._createTimeDisplayLabel();
},
_createTimeDisplayLabel: function () {
this.timeDisplayLabel = $('<label>').text('00:00');
this.timeDisplayLabel.css('left', -100);
this.timeDisplayLabel.addClass('dss-time-display-label')
this.waveFormEl.append(this.timeDisplayLabel);
this.timeDisplayLabel.animate({ top: 0, left: this.playHeadEl.position().left });
},
startPlaying: function (options) {
var that = this;
var currId = this.currentId;
this._destroyCurrent(function () {
that.currentSound = soundManager.createSound({
url: that.currentPath,
id: "com.podnoms.player-" + currId.toString(),
volume: com.podnoms.settings.volume,
whileloading: function () {
that._whileLoading();
},
whileplaying: function () {
that._whilePlaying();
}
});
if (that.currentSound) {
that.play();
if (options.success)
options.success();
//create the floating time display label
that._createTimeDisplayLabel();
}
else {
if (options.error)
options.error();
else
com.podnoms.utils.showError('Oooopsies', 'Error playing sound..');
}
});
},
stopPlaying: function () {
this._destroyCurrent();
},
stopLive: function () {
if (this.currentSound.instanceOptions.stream = true) {
this.stopPlaying();
}
},
playLive: function () {
var that = this;
var args = arguments;
this._destroyCurrent(function () {
that.currentSound = soundManager.createSound({
id: 'com.podnoms.player-live',
url: com.podnoms.settings.liveStreamRoot,
volume: 50,
stream: true,
useMovieStar: true
});
if (that.currentSound) {
that.currentSound.play();
args[0].success();
}
else {
com.podnoms.utils.showError('Oooopsies', 'Error playing sound..');
}
});
},
play: function () {
this.currentSound.play();
},
pause: function () {
this.currentSound.pause();
},
resume: function () {
this.currentSound.resume();
},
forward: function (increment) {
},
back: function (increment) {
},
setPosition: function (position) {
},
updateWaveform: function (position) {
}
}
;
com.podnoms.player.timeline = {
setupTimeline: function (options) {
}
};

View File

@@ -1,167 +0,0 @@
/** @license
----------------------------------------------
Copyright (c) 2012, Fergal Moran. All rights reserved.
Code provided under the BSD License:
*/
if (!com) var com = {};
if (!com.podnoms) com.podnoms = {};
com.podnoms.utils = {
// Asynchronously load templates located in separate .html files
loadTemplate: function (views, callback) {
var deferreds = [];
$.each(views, function (index, view) {
if (window[view]) {
deferreds.push($.get('/tpl/' + view + '/', function (data) {
window[view].prototype.template = _.template(data);
}));
} else {
alert(view + " not found");
}
});
$.when.apply(null, deferreds).done(callback);
},
trackPageView: function (url) {
if (!(typeof(_gag) == "undefined"))
_gaq.push(['_trackPageview', "/" + url]);
},
displayValidationErrors: function (messages) {
for (var key in messages) {
if (messages.hasOwnProperty(key)) {
this.addValidationError(key, messages[key]);
}
}
this.showWarning('Warning!', 'Fix validation errors and try again');
},
addValidationError: function (field, message) {
var controlGroup = $('#' + field).parent().parent();
controlGroup.addClass('error');
$('.help-inline', controlGroup).html(message);
},
removeValidationError: function (field) {
var controlGroup = $('#' + field).parent().parent();
controlGroup.removeClass('error');
$('.help-inline', controlGroup).html('');
},
modal: function (url) {
if (url.indexOf("#") == 0) {
$(url).modal('open');
} else {
$.get(url,function (data) {
$('<div class="modal hide fade">' + data + '</div>')
.modal()
.on('hidden', function () {
$(this).remove();
}
);
}).success(function () {
$('input:text:visible:first').focus();
});
}
},
showError: function (title, message) {
toastr.error(message, title);
},
showWarning: function (title, message) {
toastr.warning(message, title);
},
showAlert: function (title, message) {
toastr.success(message, title);
},
showAlertModal: function (title, message) {
},
hideAlert: function () {
$('.alert').fadeOut('slow', function () {
});
},
pad2: function (number) {
return (number < 10 ? '0' : '') + number;
},
getDateAsToday: function () {
var currentTime = new Date();
var day = currentTime.getDate();
var month = currentTime.getMonth() + 1;
var year = currentTime.getFullYear();
return (com.podnoms.utils.pad2(day) + "/" + com.podnoms.utils.pad2(month) + "/" + year);
},
formatJSONDate: function (jsonDate) {
var date = new Date(parseInt(jsonDate.substr(6)));
return date;
},
isEmpty: function (val) {
return (val === undefined || val == null || val.length <= 0) ? true : false;
},
setHashbangHeader: function (xhr) {
xhr.setRequestHeader('X-FB-Nonsense', 'Argle-Bargle');
},
generateGuid: function () {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
},
checkPlayCount: function () {
if (document.cookie.indexOf('sessionId')) {
$.getJSON('/ajax/session_play_count', function (data) {
if ((data.play_count != 0) && (data.play_count % 1) == 0) {
com.podnoms.utils.modal('tpl/PlayCountLoginAlert');
}
});
}
},
downloadURL: function downloadURL(url) {
var iframe = document.getElementById("hiddenDownloader");
if (iframe === null) {
iframe = document.createElement('iframe');
iframe.id = "hiddenDownloader";
iframe.style.visibility = 'hidden';
document.body.appendChild(iframe);
}
iframe.src = url;
},
log: function () {
try {
// Modern browsers
if (typeof console != 'undefined' && typeof console.log == 'function') {
// Opera 11
if (window.opera) {
var i = 0;
while (i < arguments.length) {
console.log('Item ' + (i + 1) + ': ' + arguments[i]);
i++;
}
}
// All other modern browsers
else if ((Array.prototype.slice.call(arguments)).length == 1 && typeof Array.prototype.slice.call(arguments)[0] == 'string') {
console.log((Array.prototype.slice.call(arguments)).toString());
} else {
console.log(Array.prototype.slice.call(arguments));
}
}
// IE8
else if ((!Function.prototype.bind || treatAsIE8) && typeof console != 'undefined' && typeof console.log == 'object') {
Function.prototype.call.call(console.log, console, Array.prototype.slice.call(arguments));
}
// IE7 and lower, and other old browsers
} catch (ignore) {
}
}
};
jQuery.extend({
handleError: function (s, xhr, status, e) {
// If a local callback was specified, fire it
if (s.error) {
s.error.call(s.context || window, xhr, status, e);
}
// Fire the global callback
if (s.global) {
(s.context ? jQuery(s.context) : jQuery.event).trigger("ajaxError", [xhr, s, e]);
}
}
});

View File

@@ -5,7 +5,7 @@ com.podnoms.settings = {
REALTIME_HOST: "{{ REALTIME_HOST }}", REALTIME_HOST: "{{ REALTIME_HOST }}",
SOCKET_IO_JS_URL: "{{ SOCKET_IO_JS_URL }}", SOCKET_IO_JS_URL: "{{ SOCKET_IO_JS_URL }}",
urlRoot: '{{ API_URL }}', urlRoot: '{{ API_URL }}',
liveEnabled: {{ LIVE_ENABLED }}', liveEnabled: {{ LIVE_ENABLED }},
liveStreamRoot: 'http://{{ LIVE_STREAM_URL }}:{{ LIVE_STREAM_PORT }}/{{ LIVE_STREAM_MOUNT }}', liveStreamRoot: 'http://{{ LIVE_STREAM_URL }}:{{ LIVE_STREAM_PORT }}/{{ LIVE_STREAM_MOUNT }}',
streamInfoUrl: 'http://{{ LIVE_STREAM_INFO_URL }}', streamInfoUrl: 'http://{{ LIVE_STREAM_INFO_URL }}',
volume: '{{ DEFAULT_AUDIO_VOLUME }}', volume: '{{ DEFAULT_AUDIO_VOLUME }}',
@@ -18,18 +18,5 @@ com.podnoms.settings = {
currentUser: {{ CURRENT_USER_ID }}, currentUser: {{ CURRENT_USER_ID }},
userName: "{{ CURRENT_USER_NAME }}", userName: "{{ CURRENT_USER_NAME }}",
userUrl: "{{ CURRENT_USER_URL }}", userUrl: "{{ CURRENT_USER_URL }}",
avatarImage: "{{ AVATAR_IMAGE }}", avatarImage: "{{ AVATAR_IMAGE }}"
/** simple helper to take an api JSON object and initialise a player item */
setupPlayerWrapper: function (id, stream_url, el) {
com.podnoms.player.setupPlayer({
id: id,
boundingEl: $('#mix-container-' + id, el),
waveFormEl: $('#waveform-' + id, el),
playHeadEl: $('#playhead-player-' + id, el),
loadingEl: $('#progress-player-' + id, el),
seekHeadEl: $('#player-seekhead', el),
playButtonEl: $('#play-pause-button-small-' + id, el),
url: stream_url || ""
});
}
}; };

View File

@@ -12,15 +12,20 @@
<li><a href="/mixes"><i class="fa fa-music fa fa-white"></i>Mixes</a></li> <li><a href="/mixes"><i class="fa fa-music fa fa-white"></i>Mixes</a></li>
<li><a href="/users"><i class="fa fa-user fa fa-white"></i>Users</a></li> <li><a href="/users"><i class="fa fa-user fa fa-white"></i>Users</a></li>
{% if user.is_authenticated %} {% if user.is_authenticated %}
<li><a href="/stream" title="Show mixes from people you follow" id="header-stream-button"><i class="fa fa-dot-circle-o fa-white"></i>Stream</a></li> <li><a href="/stream" title="Show mixes from people you follow" id="header-stream-button"><i
class="fa fa-dot-circle-o fa-white"></i>Stream</a></li>
{% endif %} {% endif %}
<li><a data-bypass="true" title="Show random mix from our vaults" id="header-random-button"><i class="fa fa-cogs fa fa-white"></i>Random</a></li> <li><a data-bypass="true" title="Show random mix from our vaults" id="header-random-button"><i
<li><a data-bypass="true" target="_blank" href="/podcast"><i class="fa fa-rss fa fa-white"></i>Podcast</a></li> class="fa fa-cogs fa fa-white"></i>Random</a></li>
<li class="purple"> <li><a data-bypass="true" target="_blank" href="/podcast"><i class="fa fa-rss fa fa-white"></i>Podcast</a>
<a data-bypass="true" class="btn-success" id="header-live-button">&nbsp;Listen Live
<i class="fa fa-headphones fa fa-white" id="header-live-icon"></i>
</a>
</li> </li>
{% if live_enabled %}
<li class="purple">
<a data-bypass="true" class="btn-success" id="header-live-button">&nbsp;Listen Live
<i class="fa fa-headphones fa fa-white" id="header-live-icon"></i>
</a>
</li>
{% endif %}
{% if user.is_authenticated %} {% if user.is_authenticated %}
<li class="purple"> <li class="purple">
<a href="/mix/upload" id='upload'>Upload <a href="/mix/upload" id='upload'>Upload
@@ -33,7 +38,8 @@
<div class="navbar-header pull-right" role="navigation"> <div class="navbar-header pull-right" role="navigation">
<ul class="nav ace-nav"> <ul class="nav ace-nav">
<li id="header-search"></li> <li id="header-search"></li>
<li><a class="btn-danger" data-bypass="true" id="header-donate-button"><i class="fa fa-euro" />Donate</a></li> <li><a class="btn-danger" data-bypass="true" id="header-donate-button"><i class="fa fa-euro"/>Donate</a>
</li>
<li class="nav ace-nav" id="header-notifications"> <li class="nav ace-nav" id="header-notifications">
<!-- End Notifications li --> <!-- End Notifications li -->
</li> </li>