Hi,
I hope one of you kind folk can help. I'm a complete coding novice, but have been making small changes to the fantastic work done by others. Thing is, there's something i want to add but have hit a brick wall.
I'd like to add different images to the left of time elapsed on the seekbar depending on the codec of the track playing. So an image for MP3, a different one for FLAC etc etc, you get the picture. Along with that, another image that appears to the left of that only if the track is greater than 16-bit. I've found scripts that do similar, but i can't get my head around what is required from them to achieve this. I've even attempted merging them into my existing edits, but have had nothing but inevitable errors A lot of Googling and some headaches later, i've decided to admit defeat and ask those that know best!
So if anyone wouldn't mind a bit of hand-holding with a complete newb it'd be very very much appreciated...just assume you're talking to a child I'm here to learn and improve my knowledge.
Code below and screenshot attached and again, thanks for any assistance guys.
// ==PREPROCESSOR==
// @name "Track Info + Seekbar + Buttons"
// @author "marc2003"
// @import "%fb2k_component_path%samples\complete\js\lodash.min.js"
// @import "%fb2k_component_path%samples\complete\js\helpers.js"
// @import "%fb2k_component_path%samples\complete\js\panel.js"
// @import "%fb2k_component_path%samples\complete\js\seekbar.js"
// ==/PREPROCESSOR==
var colours = {
background : _.RGB(30, 30, 30),
title : _.RGB(255, 255, 255),
artist : _.RGB(240, 240, 240),
codec : _.RGB(180, 180, 180),
album : _.RGB(180, 180, 180),
time : _.RGB(240, 240, 240),
seekbar_background : _.RGB(160, 160, 160),
seekbar_progress : _.RGB(255, 255, 255),
seekbar_knob : _.RGB(0, 120, 215)
};
var tfo = {
artist : fb.TitleFormat('%artist%'),
title : fb.TitleFormat('%title%'),
codec : fb.TitleFormat('%codec%'),
album : fb.TitleFormat('%album%'),
playback_time : fb.TitleFormat('%playback_time% '),
length : fb.TitleFormat(' %length%')
};
//////////////////////////////////////////////////////////////
var panel = new _.panel();
var seekbar = new _.seekbar(0, 0, 0, 0);
var buttons = new _.buttons();
var img = null;
var bs = _.scale(30);
on_playback_new_track(fb.GetNowPlaying());
buttons.update = function () {
var y = Math.round((panel.h - bs) / 1.7);
this.buttons.stop = new _.button(panel.w - LM - (bs * 13.0), y, bs, bs, {normal : 'buttons\\stop_grey_min.png'}, function () { fb.Stop(); }, 'Stop');
this.buttons.previous = new _.button(panel.w - LM - (bs * 11.7), y, bs, bs, {normal : 'buttons\\back_grey_min.png'}, function () { fb.Prev(); }, 'Previous');
this.buttons.play = new _.button(panel.w - LM - (bs * 10.4), y, bs, bs, {normal : !fb.IsPlaying || fb.IsPaused ? 'buttons\\play_grey_min.png' : 'buttons\\pause_grey_min.png'}, function () { fb.PlayOrPause(); }, !fb.IsPlaying || fb.IsPaused ? 'Play' : 'Pause');
this.buttons.next = new _.button(panel.w - LM - (bs * 9.1), y, bs, bs, {normal : 'buttons\\next_grey_min.png'}, function () { fb.Next(); }, 'Next');
this.buttons.random = new _.button(panel.w - LM - (bs * 4.9), y, bs, bs, {normal : 'buttons\\shuffle_grey_min.png'}, function () { fb.Random(); }, 'Random');
this.buttons.console = new _.button(panel.w - LM - (bs * 3.6), y, bs, bs, {normal : 'buttons\\console_grey_min.png'}, function () { fb.ShowConsole(); }, 'Console');
this.buttons.search = new _.button(panel.w - LM - (bs * 2.3), y, bs, bs, {normal : 'buttons\\search_grey_min.png'}, function () { fb.RunMainMenuCommand('Library/Search'); }, 'Library Search');
this.buttons.preferences = new _.button(panel.w - LM - bs, y, bs, bs, {normal : 'buttons\\settings_grey_min.png'}, function () { fb.ShowPreferences(); }, 'Preferences');
}
function on_size() {
panel.size();
seekbar.x = Math.round(panel.w * 0.32);
seekbar.w = panel.w - seekbar.x - _.scale(500);
seekbar.h = _.scale(12);
seekbar.y = (panel.h - seekbar.h) / 2;
buttons.update();
}
function on_paint(gr) {
gr.FillSolidRect(0, 0, panel.w, panel.h, colours.background);
buttons.paint(gr);
gr.FillSolidRect(seekbar.x, seekbar.y, seekbar.w + _.scale(6), seekbar.h, colours.seekbar_background);
if (fb.IsPlaying) {
if (img) {
_.drawImage(gr, img, 0, 0, panel.h, panel.h, image.centre);
}
gr.GdiDrawText(tfo.title.Eval(), panel.fonts.title, colours.title, panel.h + 10, 0, seekbar.x - panel.h - _.scale(60), panel.h * 0.4, LEFT);
gr.GdiDrawText(tfo.artist.Eval(), panel.fonts.normal, colours.artist, panel.h + 10, panel.h * 0.3, seekbar.x - panel.h - _.scale(60), panel.h * 0.4, LEFT);
gr.GdiDrawText(tfo.album.Eval(), panel.fonts.normal, colours.album, panel.h + 10, panel.h * 0.3, seekbar.x - panel.h - _.scale(60), panel.h * 1.0, LEFT);
gr.GdiDrawText(tfo.codec.Eval(), panel.fonts.normal, colours.codec, panel.h + 500, panel.h * 0.3, seekbar.x - panel.h - _.scale(60), panel.h * 0.4, LEFT);
gr.SetSmoothingMode(2);
if (fb.PlaybackLength > 0) {
var pos = seekbar.pos();
gr.FillSolidRect(seekbar.x, seekbar.y, pos, seekbar.h, colours.seekbar_progress);
gr.FillSolidRect(seekbar.x + pos, seekbar.y, _.scale(6), seekbar.h, colours.seekbar_knob);
gr.GdiDrawText(tfo.playback_time.Eval(), panel.fonts.normal, colours.time, seekbar.x - _.scale(45), 0, _.scale(45), panel.h, RIGHT);
gr.GdiDrawText(tfo.length.Eval(), panel.fonts.normal, colours.time, seekbar.x + seekbar.w + _.scale(6), 0, _.scale(45), panel.h, LEFT);
}
}
gr.DrawRect(seekbar.x, seekbar.y, seekbar.w + _.scale(6), seekbar.h, 1, colours.seekbar_progress);
}
function on_playback_new_track(metadb) {
if (!metadb) {
return;
}
_.dispose(img);
img = utils.GetAlbumArtV2(metadb, 0);
window.Repaint();
}
function on_playback_edited() {
window.Repaint();
}
function on_playback_seek() {
seekbar.playback_seek();
}
function on_playback_stop() {
buttons.update();
window.Repaint();
}
function on_playback_pause() {
buttons.update();
window.Repaint();
}
function on_playback_starting() {
buttons.update();
window.Repaint();
}
function on_mouse_wheel(s) {
if (seekbar.wheel(s)) {
return;
}
if (s == 1) {
fb.VolumeUp();
} else {
fb.VolumeDown();
}
}
function on_mouse_move(x, y) {
if (buttons.move(x, y)) {
return;
}
seekbar.move(x, y);
}
function on_mouse_leave() {
buttons.leave();
}
function on_mouse_lbtn_down(x, y) {
seekbar.lbtn_down(x, y);
}
function on_mouse_lbtn_up(x, y) {
if (buttons.lbtn_up(x, y)) {
return;
}
if (seekbar.lbtn_up(x, y)) {
return;
}
fb.RunMainMenuCommand('View/Show now playing in playlist');
}
function on_mouse_rbtn_up(x, y) {
return panel.rbtn_up(x, y);
}