INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Java variable set to album art  (Read 6027 times)

Marra

  • Regular Member
  • World Citizen
  • ***
  • Posts: 160
Java variable set to album art
« on: March 23, 2006, 12:40:08 pm »

Hi all,

This is from a "new" newbie trying to put to together a track info page.  My basic question is editing below text

<SCRIPT LANGUAGE="JavaScript">
imgsname="sample.jpg"

How do I replace sample.jpg with album art (tried various forms of "TRACKINFO_INSERT_IMAGE" with no luck) .

TIA

Logged

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: Java variable set to album art
« Reply #1 on: March 23, 2006, 01:14:06 pm »

Have you looked at how the other trackinfo work?
I've not written any javascript, only PHP and that was some time ago...
The following comes from the dirt simple trackinfo.

<div align="center">
  <center>
  <table border="2" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#C0C0C0" id="AutoNumber2">
    <tr>
      <td width="100%" align="center"><font face="Arial">
      <a href="TRACKINFO_INSERT_IMAGE">
      <img border="0" src="TRACKINFO_INSERT_IMAGE">[/url]</font></td>
    </tr>
  </table>
  </center>
</div>

Which appears to put the image in a table.
However unless I'm missing something it's not using javascript..
I'm not sure if that makes a difference?
I'm not to good at this stuff so my apologies if that makes no sense.
If not I'm sure someone else will pipe in!
I'm more of an application coder.

Marra

  • Regular Member
  • World Citizen
  • ***
  • Posts: 160
Re: Java variable set to album art
« Reply #2 on: March 23, 2006, 08:54:51 pm »

Thanks Mr Chriz for the reply.  I'm aware of the HTML code you have outlined above but what I need specifically is the java script so I can alter freely available java source codes to access MC fields. Any one with javascript experience out there ?
Logged

Marra

  • Regular Member
  • World Citizen
  • ***
  • Posts: 160
Re: Java variable set to album art
« Reply #3 on: March 25, 2006, 01:27:12 pm »

Any other thoughts?
Logged

Marra

  • Regular Member
  • World Citizen
  • ***
  • Posts: 160
Re: Java variable set to album art
« Reply #4 on: March 28, 2006, 10:31:24 pm »

Time to re-word this:

I've looked at several freeware scripts using Javascript to inlcude in a Trackinfo template I'm developing (fancy scrolling, image transitions etc). I can include with no problems the following :

<SCRIPT>
// Your messages. Add as many as you like
var text=new Array()
text[0]="TRACKINFO_INSERT_TITLE"
text[1]="TRACKINFO_INSERT_ARTIST"
text[2]="TRACKINFO_INSERT_ALBUM"

and I get the playing now details.

But I have no luck with getting the album art :

<SCRIPT LANGUAGE="JavaScript">
<!-- Beginning of JavaScript -
// the URL of your images. Add as many images as you like
var imgsname = new Array()
imgsname[0]="samplepicA.jpg"
imgsname[1]="TRACKINFO_INSERT_IMAGE"

or imgsname[1]=TRACKINFO_INSERT_IMAGE

or imgsname[1]="TRACKINFO_INSERT_IMAGE.jpg"

I am missing some code but what?  Sorry for being a pain about this but I would appreciate a way around this stumbling block.  TIA


Logged

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: Java variable set to album art
« Reply #5 on: March 29, 2006, 03:17:30 am »

I've had another thought on this.
When you use the trackinfo visualisations
Media Center takes your HTML page, which in your case
contains Javascript and goes through it replacing all
special tags such as TRACKINFO_INSERT_TITLE
with there respective information, so
TRACKINFO_INSERT_TITLE may become
"Wish you were here"
If you were listening to Pinkfloyds Wish You were Here.
When it gets to the TrackInfo_Insert_Image it must
have an image file which it can link to.
For this reason it actually makes a copy of the JPG
file to somewhere convienient, and links to this convienient place.
Once finished it then saves the new HTML document
to Generated.html, which is saved in the same directory
as the trackinfo's index.html.
You can open Generated.html in a standard editor and see where the
image is linked to.

Here is one that I just done
M:\DOCUME~1\Chris\LOCALS~1\Temp\JRTemp\APE Image - 2856.jpg

I'm wondering, does Javascript use '\' as an escape character?
If so that path wouldn't work.  The only way you could
put it right is to place TrackInfo_Insert_Album in a string
and then parse through inserting an extra \ where ever
necassery.

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: Java variable set to album art
« Reply #6 on: March 29, 2006, 03:34:53 am »

Thinking about this a bit more, could you take a generated.html
that uses javascript
change the '\'' to '/' and report back here if it works?

Marra

  • Regular Member
  • World Citizen
  • ***
  • Posts: 160
Re: Java variable set to album art
« Reply #7 on: March 29, 2006, 09:56:13 pm »

Thanks Mr ChriZ for sticking with me on this.

I've followed your suggestions and have managed to get the image file (in my case "c:/windows/temp/JRTemp/MP3 Image - 3048.jpg" with "\"
replaced by "/")  to display.  That's fine for the current track only.

So all I need to do hopefully using javascript is to make these replacements  (/ to \) to get all images to display.  Now I'm stepping from my limited HTML knowledge to javascript.  A quick google leads me to
 string.replace(/replacethis/g,"withthis");  where g is global change all instances.

imgsname="TRACKINFO_INSERT_IMAGE".replace(///g,"\");

This isn't giving the correct result. Is it confused by too may "/"s in code or is there some other error. If PollyQ is out there, I'm sure he/she could help .  Thanks again.
Logged

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: Java variable set to album art
« Reply #8 on: March 30, 2006, 03:54:48 am »

Actually the reason I asked you to try this was I believe
it would be better if MC actually put them that way round,
this way no extra code would be required, and it would
still work in normal HTML.

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42385
  • Shoes gone again!
Re: Java variable set to album art
« Reply #9 on: March 30, 2006, 07:58:47 pm »

I'm afraid something else might break if we always used forward slashes.  For now, replacement of slashes may be the way to go.
Logged
Matt Ashland, JRiver Media Center

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: Java variable set to album art
« Reply #10 on: March 31, 2006, 03:07:41 am »

Not to worry.

Marra according to what you wrote as the function parameters
string.replace(/replacethis/g,"withthis"); 

you appear to have things the wrong way round:
imgsname="TRACKINFO_INSERT_IMAGE".replace(///g,"\");

Replace uses regular expressions... I'll see if I can work it out....
I'd be trying this
imgsname="TRACKINFO_INSERT_IMAGE".replace(/\\/g,"\\\\")
to go from
"C:\MyTest\Here\We\Go"
to
"C:\\MyTest\\Here\\We\\Go"

or
imgsname="TRACKINFO_INSERT_IMAGE".replace(/\\/g,"/")
for
C:/MyTest/Here/We/Go

Give it a go!
I used The Regex Coach
http://www.weitz.de/regex-coach/
which is very useful for Regular expressions

I have to say Javascript has really bad syntax! I can't believe the
first parameter get's away with not being in quotes.

Marra

  • Regular Member
  • World Citizen
  • ***
  • Posts: 160
Re: Java variable set to album art
« Reply #11 on: March 31, 2006, 06:09:03 am »

Backward-forward slashes ////  \\\\\. Yes I did have them the wrong way around. Tried  as you suggested but the replace command seems to be doing nothing. I even tried replacing a letter with no luck. The generated file shows
imgsname[1]="c:\windows\temp\JRTemp\MP3 Image - 1256.jpg".replace(/\/g,"/")
or similar, whatever I do.  No, it's not time to slash my wrists but this is frustrating.  Does the code have to be written over 2 lines?  I'm guessing, I'm lost, I'm tired.  Thanks again Mr ChriZ -  tomorrow another day
Logged

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: Java variable set to album art
« Reply #12 on: March 31, 2006, 06:54:35 am »

My apologies I think you may have saw my post prior to me editing
it. 
I changed
replace(/\/g,"/")
to
replace(/\\/g,"/")

The replace command is going to be done by the javascript
not by the compilation stuff MC does, so

imgsname[1]="c:\windows\temp\JRTemp\MP3 Image - 1256.jpg".replace(/\\/g,"/")

is what I'd expect to see in the generated output.

Maybe you need to place it in a seperate string first though...
so...
var temp = "TRACKINFO_INSERT_IMAGE"
imgsname[1]=temp.replace(/\\/g,"/")

Just wondering if theres a messagebox you could use to test the output...
Just looked it up...
and it appears you can use
alert("message");
so....
alert(imgsname[1]);
should show you whats contained in imgsname[1]
and give you some idea of whats going wrong, if it still is going wrong.

If you still can't get it to work, feel free to post the entire script here
and I'll take a look at it.

Marra

  • Regular Member
  • World Citizen
  • ***
  • Posts: 160
Re: Java variable set to album art
« Reply #13 on: March 31, 2006, 11:26:47 am »

I couldn't sleep.  Maybe getting somewhere

alert("TRACKINFO_INSERT_IMAGE")
gives an alert      c:windowstempJRTempMP3 Image - 3316.jpg
That's right - no slashes (and the t in temp is a small box).

But the generated.html shows
"c:\windows\temp\JRTemp\MP3 Image - 3316.jpg"

Have proved code correct by replacing letters (this case "e")

var temp = "TRACKINFO_INSERT_IMAGE"
alert("TRACKINFO_INSERT_IMAGE");
var temp1=temp.replace(/e/g,"/")
alert(temp1)

I guess the problem is there are no slashes to replace despite what the generated.html shows.  Dead end?

Logged

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: Java variable set to album art
« Reply #14 on: March 31, 2006, 01:12:11 pm »

I've got a script set up now... and my previous soloution didn't work
bare with me...

You were right :-S

You aren't the first person to try this with JRiver templates!
Usenet post!

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: Java variable set to album art
« Reply #15 on: March 31, 2006, 01:45:44 pm »

____________________________________________________________
<HTML>
<HEAD>
<meta name="FILEPATH" content="TRACKINFO_INSERT_IMAGE" />
<script>
    var metas = document.getElementsByTagName("meta");


   for (i = 0; i < metas.length; i++)
   {
      if (metas.item(i).getAttribute("name") == "FILEPATH")
      {
         myfile = metas.item(i).getAttribute("content");
         break;
      }
   }
                Alert(myFile);


</script>
</BODY>
</HTML>
_____________________________________________

Forget everything i said previously.
This is a hack to say the least, but it should work.
Give it ago!

Marra

  • Regular Member
  • World Citizen
  • ***
  • Posts: 160
Re: Java variable set to album art
« Reply #16 on: March 31, 2006, 04:11:29 pm »

Mr ChriZ, so so so close.
Entered above, gives error 'myfile' is undefined.
select ...continue running script... Yes and all works perfectly.  Just need to remove this small error.  I dare not touch your fantastic 'hack'. TIA
Logged

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: Java variable set to album art
« Reply #17 on: March 31, 2006, 04:37:08 pm »

Lol, I can't claim the  credit it for it,
I found something similar with a usenet search and modified it slightly.

I don't get that error. Weird!
but I guess just stick
var myfile;
in front of the for loop, should do it.
You can change the name myfile to whatever you like.
That was from the stuff i copied...

How it works is actually quite simple.
HTML allows metadata to be loaded.  HTML doesn't use escape
characters or at least not the same as javascript.
Javascript can load the meta data however, and expects the HTML
not to contain escape characters so converts "\"'s to "\\".
The for loop searches for the meta data that has the Attribute Name
FILEPATH, and when it finds it retrieves the content which is
your filepath.


Marra

  • Regular Member
  • World Citizen
  • ***
  • Posts: 160
Re: Java variable set to album art
« Reply #18 on: March 31, 2006, 06:27:41 pm »

Mr ChriZ
You're not gonna believe this.  I can't get rid of this error.
Tried :

<meta name="FILEPATH" content="TRACKINFO_INSERT_IMAGE" />
<script>
    var myfile=" ";
    var metas = document.getElementsByTagName("meta"); etc etc

Tried var myfile
         var myfile=" "
         var myfile;
          var myfile=" ";

No luck?   

Logged

Marra

  • Regular Member
  • World Citizen
  • ***
  • Posts: 160
Re: Java variable set to album art
« Reply #19 on: April 01, 2006, 01:01:46 am »

Yes, fixed. Simply removed "Alert(myFile);" and works fine.  Thanks Mr ChriZ for all your patience and help.  I certainly owe ya a beer!
Logged

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: Java variable set to album art
« Reply #20 on: April 01, 2006, 04:33:48 am »

Yes, fixed. Simply removed "Alert(myFile);" and works fine.  Thanks Mr ChriZ for all your patience and help.  I certainly owe ya a beer!


Your welcome!  Glad you got it fixed!
Pages: [1]   Go Up