From 849cec8bc99528356bdda378083a64835ab2ce68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Sipos?= Date: Thu, 4 Aug 2016 19:18:49 +0200 Subject: [PATCH 1/2] Added multiple audio track selection menu --- index.js | 231 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 199 insertions(+), 32 deletions(-) diff --git a/index.js b/index.js index 1a3a503..e4db3ae 100644 --- a/index.js +++ b/index.js @@ -16,7 +16,7 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ -// WebChimera.js Player v6.0.1 +// WebChimera.js Player v0.5.8 var vlcs = {}, opts = {}, @@ -70,7 +70,7 @@ window.addEventListener('beforeunload', function(e) { function wjs(context) { - this.version = "v6.0.1"; + this.version = "v0.5.8"; // Save the context this.context = (typeof context === "undefined") ? "#webchimera" : context; // if no playerid set, default to "webchimera" @@ -220,8 +220,6 @@ wjs.prototype.prev = function() { wjs.prototype.addPlayer = function(wcpSettings) { - if (!wcpSettings["wcjs"]) console.error(new Error('Missing `wcjs` parameter in `.addPlayer()`')); - if (wcpSettings) newid = (typeof wcpSettings["id"] === "undefined") ? "webchimera" : wcpSettings["id"]; // if no id set, default to "webchimera" else newid = "webchimera"; @@ -254,10 +252,11 @@ wjs.prototype.addPlayer = function(wcpSettings) { opts[newid].crop = "Default"; opts[newid].zoom = 1; if (typeof opts[newid].allowFullscreen === 'undefined') opts[newid].allowFullscreen = true; - - playerbody = '
Playlist Menu
    Subtitle Menu
      Audio menu
        + //line 307: toolbar button actions + playerbody = '
        Playlist Menu
          Subtitle menu
            Audio menu
              -1) wjsResponse.ext = wjsResponse.ext.substr(0,wjsResponse.ext.indexOf('[')); + return wjsResponse; + } + wjsIndex++; + } + return; + } + } + return; + } else return console.error("Value sent to .audDesc() needs to be a number."); +} + +wjs.prototype.audioCount = function() { + wjsIndex = this.vlc.audio.count; + var itemSetting = this.itemDesc(this.currentItem()).setting; + if (itemSetting.audios) { + itemAudios = itemSetting.audios; + if (wjsIndex == 0) wjsIndex = 1; + for (var newDesc in itemAudios) if (itemAudios.hasOwnProperty(newDesc)) wjsIndex++; + return wjsIndex; + } + return wjsIndex; +} +wjs.prototype.audioTrack = function(newTrack) { + if (typeof newTrack === 'number') { + if (newTrack == 0) { + this.vlc.audio.track = 0; + //clearAudios.call(this); + } else { + if (newTrack < this.vlc.audios.count) { + this.find(".wcp-audio-text").html(""); + opts[this.context].audios = []; + this.vlc.audio.track = newTrack; + } else { + this.find(".wcp-audio-text").html(""); + opts[this.context].audios = []; + + if (this.vlc.audio.track > 0) { + this.vlc.audio.track = 0; + newAud = newTrack - this.vlc.audio.count +1; + } else newSub = newTrack - this.vlc.audio.count; + + itemAudios = this.itemDesc(this.currentItem()).setting.audios; + for (var k in itemAudios) if (itemAudios.hasOwnProperty(k)) { + newAud--; + if (newAud == 0) { + //loadSubtitle.call(this,itemSubtitles[k]); + break; + } + } + } + opts[this.context].currentAud = newTrack; + //printAudios.call(this); + } + } else return opts[this.context].currentAud; return this; } + wjs.prototype.audioDelay = function(newDelay) { if (typeof newDelay === 'number') this.vlc.audio.delay = newDelay; else return this.vlc.audio.delay; @@ -817,11 +892,9 @@ wjs.prototype.volume = function(newVolume) { this.vlc.mute = true; } this.find(".wcp-vol-bar-full").css("width", "0px"); - } else if (newVolume && !isNaN(newVolume) && newVolume > 0 && newVolume <= 200) { + } else if (newVolume && !isNaN(newVolume) && newVolume > 5 && newVolume <= 200) { if (this.vlc.mute) this.vlc.mute = false; - if(newVolume > 200) newVolume = 200; - if (newVolume > 150) this.find(".wcp-vol-button").removeClass("wcp-mute").removeClass("wcp-volume-medium").removeClass("wcp-volume-low").addClass("wcp-volume-high"); else if (newVolume > 50) this.find(".wcp-vol-button").removeClass("wcp-mute").removeClass("wcp-volume-high").removeClass("wcp-volume-low").addClass("wcp-volume-medium"); else this.find(".wcp-vol-button").removeClass("wcp-mute").removeClass("wcp-volume-medium").removeClass("wcp-volume-high").addClass("wcp-volume-low"); @@ -1166,6 +1239,13 @@ wjs.prototype.subtitles = function(newBool) { } else return this.find(".wcp-subtitles")[0]; } +wjs.prototype.audios = function(newBool) { + if (typeof newBool !== 'undefined') { + if (newBool === true) return showAudios.call(this); + else return hideAudios.call(this); + } else return this.find(".wcp-audios")[0]; +} + wjs.prototype.ui = function(newBool) { if (typeof newBool !== 'undefined') { if (newBool === true) { @@ -1236,11 +1316,6 @@ function fullscreenOn() { switchClass(this.find(".wcp-maximize"),"wcp-maximize","wcp-minimize"); - var that = this; - setTimeout(function() { - singleResize.call(that, that.canvas.width, that.canvas.height); - }, 200); - return true; } else return false; } @@ -1268,12 +1343,6 @@ function fullscreenOff() { this.wrapper.css({cursor: 'pointer'}); if (!this.vlc.mute) this.vlc.mute = true; } - - var that = this; - setTimeout(function() { - singleResize.call(that, that.canvas.width, that.canvas.height); - }, 200); - return true; } else return false; } @@ -1339,10 +1408,13 @@ function isMediaChanged() { this.find(".wcp-subtitle-text").html(""); if (this.find(".wcp-subtitles").is(":visible")) this.find(".wcp-subtitles").hide(0); this.find(".wcp-subtitle-but").hide(0); + + if (this.find(".wcp-audios").is(":visible")) this.find(".wcp-audios").hide(0); + this.find(".wcp-audio-but").hide(0); opts[this.context].firstTime = true; - vlcs[this.context].renderer.clear(this.canvas); + vlcs[this.context].renderer.clearCanvas(); } function isBuffering(percent) { @@ -1370,6 +1442,7 @@ function isPlaying() { opts[this.context].currentSub = 0; opts[this.context].trackSub = -1; totalSubs = this.vlc.subtitles.count; + totalAudios = this.vlc.subtitles.count-1; itemSetting = this.itemDesc(this.currentItem()).setting; // set default aspect ratio @@ -1398,6 +1471,7 @@ function isPlaying() { opts[this.context].subDelay = 0; if (totalSubs > 0) this.find(".wcp-subtitle-but").show(0); + if (totalAudios > 0) this.find(".wcp-audio-but").show(0); vlcs[this.context].events.emit('FirstPlay'); } @@ -1525,7 +1599,12 @@ function hideUI() { function showPlaylist() { if (!this.find(".wcp-playlist").is(":visible")) { - if (this.find(".wcp-subtitles").is(":visible")) this.find(".wcp-subtitles").hide(0); + if (this.find(".wcp-subtitles").is(":visible")) { + this.find(".wcp-subtitles").hide(0); + } + if (this.find(".wcp-audios").is(":visible")) { + this.find(".wcp-audios").hide(0); + } this.find(".wcp-playlist").show(0); printPlaylist.call(this); } @@ -1544,11 +1623,32 @@ function showSubtitles() { this.find(".wcp-playlist-items").sortable("destroy"); this.find(".wcp-playlist").hide(0); } + if (this.find(".wcp-audios").is(":visible")) { + this.find(".wcp-audios").hide(0); + } this.find(".wcp-subtitles").show(0); printSubtitles.call(this); } } +function hideSubtitles(){if(this.find(".wcp-subtitles").is(":visible"))this.find(".wcp-subtitles").hide(0)} + +function showAudios() { + if (!this.find(".wcp-audios").is(":visible")) { + if (this.find(".wcp-playlist").is(":visible")) { + this.find(".wcp-playlist-items").sortable("destroy"); + this.find(".wcp-playlist").hide(0); + } + if (this.find(".wcp-subtitles").is(":visible")) { + this.find(".wcp-subtitles").hide(0); + } + this.find(".wcp-audios").show(0); + printAudios.call(this); + } +} + +function hideAudios(){if(this.find(".wcp-audios").is(":visible"))this.find(".wcp-audios").hide(0)} + function printPlaylist() { playlistItems = this.find(".wcp-playlist-items"); oi = 0; @@ -1791,6 +1891,74 @@ function processSub(srt,extension) { opts[this.context].trackSub = -1; } +function printAudios() { + playlistItems = this.find(".wcp-audios-items"); + + generatePlaylist = ""; + generatePlaylist += '
            • Mute
            • '; + if (this.vlc.audio.count > 0) { + for (oi = 1; oi < this.vlc.audio.count; oi++) { + generatePlaylist += '
            • '+this.vlc.audio[oi]+'
            • '; + } + } else oi = 1; + + itemSetting = this.itemDesc(this.currentItem()).setting; + + if (itemSetting.audios) { + itemAudios = itemSetting.audios; + for (var k in itemAudios) if (itemAudios.hasOwnProperty(k)) { + generatePlaylist += '
            • '+k+'
            • '; + oi++; + } + } + + playlistItems.html(""); + playlistItems.html(generatePlaylist); + + if (playlistItems.outerHeight() < (oi* parseInt(playlistItems.find(".wcp-audios-item").css("height")))) { + playlistItems.css("cursor","pointer"); + } else playlistItems.css("cursor","default"); + + this.find(".wcp-audios-item").click(function() { + wjsPlayer = getContext(this); + if ($(this).index() == 0) { + wjsPlayer.vlc.audio.track = 0; + //clearAudios.call(wjsPlayer); + // wjsPlayer.notify("Subtitle Unloaded"); + } else if ($(this).index() < wjsPlayer.vlc.audio.count) { + wjsPlayer.find(".wcp-audio-text").html(""); + opts[wjsPlayer.context].audios = []; + wjsPlayer.vlc.audio.track = $(this).index(); + wjsPlayer.notify("Audio: "+wjsPlayer.audioDesc($(this).index()).language); + } else { + wjsPlayer.find(".wcp-audio-text").html(""); + opts[wjsPlayer.context].audios = []; + if (wjsPlayer.vlc.audio.track > 0) wjsPlayer.vlc.audio.track = 0; + newAud = $(this).index() - wjsPlayer.vlc.audios.count; + if (wjsPlayer.vlc.audio.count) newAud++; + itemAudios = itemSetting.audios; + for (var k in itemAudios) if (itemAudios.hasOwnProperty(k)) { + newAud--; + if (newAud == 0) { + loadAudio.call(wjsPlayer,itemAudios[k]); + wjsPlayer.notify("Audio: "+k); + break; + } + } + } + wjsPlayer.find(".wcp-audios").hide(0); + opts[wjsPlayer.context].currentAud = $(this).index(); + opts[wjsPlayer.context].audioDelay = 0; + }); + +} + function preventSleep() { powerSaveBlocker?(!sleepId||!powerSaveBlocker.isStarted(sleepId))?sleepId=powerSaveBlocker.start('prevent-display-sleep'):false:sleep.prevent(); } @@ -1830,7 +1998,6 @@ function strip(s){return s.replace(/^\s+|\s+$/g,"")} function gcd(a,b){if(b>a){temp=a;a=b;b=temp}while(b!=0){m=a%b;a=b;b=m;}return a} function sel(context){return $($(this).parents(".wcp-wrapper")[0]).find(context)} function switchClass(el,fclass,sclass){if(el.hasClass(fclass))el.removeClass(fclass).addClass(sclass)} -function hideSubtitles(){if(this.find(".wcp-subtitles").is(":visible"))this.find(".wcp-subtitles").hide(0)} wjs.prototype.audioCount=function(){return this.vlc.audio.count} wjs.prototype.itemCount=function(){return this.vlc.playlist.itemCount} wjs.prototype.playing=function(){return this.vlc.playing} From 69b155982f8883092732df693721a708c255a455 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Sipos?= Date: Thu, 4 Aug 2016 19:20:12 +0200 Subject: [PATCH 2/2] Added audio menu CSS, temporary icon for now. --- css/general.css | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/css/general.css b/css/general.css index 7303cd9..b31a75a 100644 --- a/css/general.css +++ b/css/general.css @@ -174,6 +174,11 @@ padding-left: 14px; } +.wcp-audios-item { + width: calc(100% - 14px); + padding-left: 14px; +} + .sortable-dragging { cursor: -webkit-grabbing !important; background-color: #3d3d3d !important; @@ -410,6 +415,10 @@ /* .wcp-subtitle-but { display: none } */ .wcp-subtitle-but:before { content: "\E83A"; font-size: 23px } +/* Audios Button */ +/* .wcp-audio-but { display: none } */ +.wcp-audio-but:before { content: "\E801"; font-size: 23px } + /* Fullscreen Button Icons */ .wcp-minimize:before { content: "\E805"; font-size: 24px } .wcp-maximize:before { content: "\E804"; font-size: 24px } @@ -474,6 +483,20 @@ text-align: center } +/* Audio Text */ +.wcp-audio-text { + font-family: 'Roboto'; + position: absolute; + bottom: 40px; + left: 0; + width: 100%; + font-size: 20px; + z-index: 2; + color: #fff; + text-shadow: -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000; + text-align: center +} + .wcp-tooltip { position: absolute; z-index: 1070; @@ -511,4 +534,4 @@ text-decoration: none; background-color: #000; border-radius: 2px; -} \ No newline at end of file +}