Compare commits

..

No commits in common. "3979d358d0801c595cd0e1ba80f32becb9c177fb" and "19c568d27a5ff9ae34dec034015ba69339b3ab52" have entirely different histories.

5 changed files with 352 additions and 406 deletions

2
.gitignore vendored
View File

@ -1,5 +1,3 @@
dist/js/*.js
dist/css/*.css
dist/css/*.svg
package-lock.json
node_modules

View File

@ -1,8 +0,0 @@
{
"js": {
"type": "terser",
"terser": {
"mangle": false
}
}
}

View File

@ -1,18 +0,0 @@
{
"name": "myplayer",
"version": "1.0.0",
"description": "A Web-MP3-Player with Playlist Support",
"main": "src/player.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://tk-sls.de/git/tk-sls.de/myplayer.git"
},
"author": "tilt <tilt@linuxfoo.de>",
"license": "MIT",
"dependencies": {
"minify": "^11.4.1"
}
}

View File

@ -12,8 +12,8 @@ if ! cd "$dir" ; then
elif ! mkdir -p "$jsdir" ; then
echo "ERROR: Could not create directory $jsdir; aborted." >&2 ;
exit 1 ;
elif ! type minify > /dev/null ; then
echo "ERROR: Executable \"minify\" not found in PATH; aborted." >&2 ;
elif ! type yui-compressor > /dev/null ; then
echo "ERROR: Executable \"yui-compressor\" not found in PATH; aborted." >&2 ;
exit 1 ;
fi
@ -47,7 +47,7 @@ do
done
echo "INFO: Compressing player.js ..." >&2
minify player.js >> "$jsdir"/myplayer.min.js
yui-compressor player.js >> "$jsdir"/myplayer.min.js
chmod 644 "$jsdir"/myplayer.min.js

View File

@ -21,29 +21,26 @@
* THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE */
var MyPlayer = function(_args) {
var failed = false,
detached = false,
player = null,
args_default = {
autoplay: false,
css: { "height": "500px" },
detachable: true,
element: "body",
id3: false,
list: [],
loop: true,
mode: "mp3url",
shuffle: false,
waveform: false
},
args = (_args===undefined) ? args_default : $.extend({}, args_default, _args),
mimeTypeFromSrc = function(src) {
var extension = src.split(".").pop().toLowerCase();
var failed = false;
var detached = false;
var player = null;
var types = {
"3g2": "video/3gpp2",
"3gp": "video/3gpp",
"7z": "application/x-7z-compressed",
var defaultArgs = {
detachable: true,
element: 'body',
id3: false,
mode: 'mp3url',
waveform: false,
autoplay: false,
loop: true,
shuffle: false,
list: []
};
var mimeTypeFromSrc = function(src) {
var extension = src.split('.').pop().toLowerCase();
return {
"aac": "audio/aac",
"abw": "application/x-abiword",
"arc": "application/x-freearc",
@ -58,10 +55,11 @@ var MyPlayer = function(_args) {
"css": "text/css",
"csv": "text/csv",
"doc": "application/msword",
"docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"eot": "application/vnd.ms-fontobject",
"epub": "application/epub+zip",
"gif": "image/gif",
"gz": "application/gzip",
"gif": "image/gif",
"htm": "text/html",
"html": "text/html",
"ico": "image/vnd.microsoft.icon",
@ -87,10 +85,11 @@ var MyPlayer = function(_args) {
"ogx": "application/ogg",
"opus": "audio/opus",
"otf": "font/otf",
"png": "image/png",
"pdf": "application/pdf",
"php": "application/x-httpd-php",
"png": "image/png",
"ppt": "application/vnd.ms-powerpoint",
"pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
"rar": "application/vnd.rar",
"rtf": "application/rtf",
"sh": "application/x-sh",
@ -111,30 +110,40 @@ var MyPlayer = function(_args) {
"woff2": "font/woff2",
"xhtml": "application/xhtml+xml",
"xls": "application/vnd.ms-excel",
"xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"xml": "application/xml",
"xul": "application/vnd.mozilla.xul+xml",
"zip": "application/zip"
"zip": "application/zip",
"3gp": "video/3gpp",
"3g2": "video/3gpp2",
"7z": "application/x-7z-compressed"
}[extension] || "application/octet-stream";
};
return types[extension] || "application/octet-stream";
},
createAudio = function() {
var args = (typeof(_args)==='undefined')
? defaultArgs
: $.extend({}, defaultArgs, _args);
var createAudio = function() {
var autoplay = args.autoplay ? 'autoplay="true"' : '';
var styles = [];
var style;
var key;
for (key in args.css) {
var value = args.css[key];
styles.push(`${key}: ${value}`);
}
$(args.element).append(
'<audio id="myplayer" controls="controls" ' + autoplay + '>'+
'<p>'+
'Your browser does not understand '+
'the &lt;audio&gt; tag. '+
'</p>'+
'</audio>'
);
style = styles.join(" ");
args.audio = $(`<audio id="myplayer" controls="controls" style="${style}" ${autoplay}></audio>`);
console.log("DEBUG: appending audio=", args.audio, " to element=", args.element, " ...");
$(args.element).append(args.audio);
},
readId3 = function() {
args.audio = args.element + ' audio';
$(args.audio).css({
'height': '500px',
});
};
var readId3 = function() {
$(args.element).find('ul.mejs li').each(function(i, track){
var url = $(track).attr('data-url');
@ -145,57 +154,35 @@ var MyPlayer = function(_args) {
var tags = tag.tags;
var track_title;
if(typeof(tags.title)!='undefined') {
if(typeof(tags.title)!='undefined')
track_title = tags.title;
}
else {
else
track_title = url;
}
if(typeof(tags.artist)!='undefined') {
if(typeof(tags.artist)!='undefined')
track_title = tags.artist + ' - ' + track_title;
}
$(args.element).find('ul.mejs li').each(function(j, _track){
if(i==j) {
if(i==j)
$(_track).html(track_title);
}
});
}
});
});
},
playerCreated = function(mediaElement, originalNode, instance) {
};
var playerCreated = function() {
restoreParams();
if(args.shuffle) {
instance.shuffleCallback();
}
if(args.loop) {
instance.loopCallback();
}
if(args.id3) {
if(args.id3)
readId3();
}
},
createPlayer = function() {
};
var createPlayer = function() {
player = new MediaElementPlayer(
"myplayer", {
success: playerCreated,
features: [
'playpause',
'current',
'progress',
'duration',
'volume',
'playlist',
'prevtrack',
'nexttrack',
'shuffle',
'loop'
]
features: ['playpause', 'current', 'progress', 'duration', 'volume', 'playlist', 'prevtrack', 'nexttrack', 'shuffle', 'loop']
});
$(args.element).append(
@ -203,25 +190,25 @@ var MyPlayer = function(_args) {
'The player is currently detached.'+
'</p>'
);
},
param = function(name) {
};
var param = function(name) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for(i=0; i<vars.length; i++) {
for(var i=0; i<vars.length; i++) {
var pair = vars[i].split("=");
if(pair[0] == name) {
if(pair[0] == name)
return pair[1];
}
}
return false;
},
setupDetach = function() {
if(!args.detachable) {
};
var setupDetach = function() {
if(!args.detachable)
return;
}
var popup = function(url) {
player.pause();
@ -235,9 +222,8 @@ var MyPlayer = function(_args) {
'resizable=false'
);
if(window.focus) {
if(window.focus)
playerWindow.focus();
}
$("iframe",top.document).height(20);
@ -262,9 +248,8 @@ var MyPlayer = function(_args) {
var trackNo = 0;
$(args.element).find('ul.mejs li').each(function(i){
if($(this).hasClass('current')) {
if($(this).hasClass('current'))
trackNo = i;
}
});
popup(
@ -286,11 +271,11 @@ var MyPlayer = function(_args) {
$('.playerDetached', opener.document).hide();
};
}
},
restoreParams = function() {
if(!detached) {
};
var restoreParams = function() {
if(!detached)
return;
}
var paused = (param('paused') && param('paused')=='true');
var currentTime = param('currentTime') ? parseFloat(param('currentTime')) : 0.0;
@ -306,20 +291,19 @@ var MyPlayer = function(_args) {
}
});
if(paused) {
if(paused)
player.pause();
}
};
if(param('popup')!==false) {
detached = true;
$('body').html(
'<div ' +
'id="myplayer" ' +
'style="' +
'width: ' + $(args.element).width() + 'px; '+
'height: ' + $(args.element).height() + ' px;'+
'<div '+
'id="myplayer" '+
'style="'+
'width: '+$(args.element).width()+'px; '+
'height: '+$(args.element).height()+' px;'+
'"></div>'
);
@ -327,7 +311,6 @@ var MyPlayer = function(_args) {
}
if(args.mode=='mp3url') {
console.log("args.mode=", args.mode);
var mp3url = (typeof args.mp3url === "undefined")
? $(location).attr('href').replace(/\?.*/, '').replace(/\/[^\/]+\/?$/, '')
: args.mp3url;
@ -336,15 +319,12 @@ var MyPlayer = function(_args) {
url: mp3url,
type: 'GET',
success: function(res) {
var doc;
var head;
doc = document.createElement('html');
createAudio();
var doc = document.createElement('html');
doc.innerHTML = res;
head = $(doc).find('a').each(function(idx,item) {
var head = $(doc).find('a').each(function(idx,item) {
var src = $(item).attr('href');
if(src.match(/\.mp3$/)) {
@ -352,7 +332,7 @@ var MyPlayer = function(_args) {
var title = item.innerHTML;
var type = "audio/mpeg";
args.audio.append(`<source src="${url}" type="${type}" title="${title}"/>`);
$(args.audio).append('<source src="'+url+'" type="' + type + '" title="'+title+'"/>');
}
});
@ -370,77 +350,71 @@ var MyPlayer = function(_args) {
$.get(m3u, function(txt){
var lines = txt.split("\n");
var len = lines.length;
var i = 0;
while(i < len) {
for(var i = 0, len = lines.length; i < len; i++)
if(!lines[i].match(/^[ \t]*#/) && lines[i].match(/\.mp3$/)) {
var mp3 = lines[i];
var title = unescape(mp3.split('/').pop());
var type = "audio/mpeg";
args.audio.append(`<source src="${mp3}" type="${type}" title="${title}"/>`);
$(args.audio).append('<source src="'+mp3+'" type="' + type + '" title="'+title+'"/>');
}
i++;
}
console.log("DEBUG: mode==m3u audio=",$(args.audio));
createPlayer();
setupDetach();
});
}
else if(args.mode=='list') {
var len = args.list.length;
var i = 0;
createAudio();
while(i < len) {
for(var i = 0, len = args.list.length; i < len; i++) {
var item = args.list[i];
var type = typeof item;
var src = '';
var title = '';
var type;
if(item !== null && type === 'object') {
if(item.url) {
if(item.url)
src = item.url;
}
else {
alert(`MyPlayer: item[${i}]: property "url" is missing.`);
i++;
alert(
'MyPlayer: item[' + i + ']: '+
'property "url" is missing.'
);
continue;
}
if(item.title) {
if(item.title)
title = item.title;
}
else {
else
title = url.replace(/(.*\/)?([^\/]+)/, '$2');
}
}
else if(type === 'string') {
src = item;
title = src;
}
else {
alert(`MyPlayer: item[${i}]: unsupported type=${type}.`);
i++;
alert(
'MyPlayer: item [' + i + ']: '+
'unsupported type "' + type + '"'
);
continue;
}
type = mimeTypeFromSrc(src);
var type = mimeTypeFromSrc(src);
args.audio.append(`<source src="${src}" type="${type}" title="${type}"/>`);
i++;
$(args.audio).append('<source src="'+src+'" type="' + type + '" title="'+title+'"/>');
}
createPlayer();
setupDetach();
}
else {
$(args.element).append(`<p>Unsupported mode ${args.mode}"</p>`);
$(args.element).append('<p>Unsupported mode "'+args.mode+'"</p>');
failed = true;
}
};