INTERACT FORUM
Windows => Plug-in Development => Topic started by: Marra 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
-
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.
-
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 ?
-
Any other thoughts?
-
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
-
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.
-
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?
-
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.
-
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.
-
I'm afraid something else might break if we always used forward slashes. For now, replacement of slashes may be the way to go.
-
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.
-
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
-
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.
-
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?
-
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! (http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/1497aa1dbcead04d/cf8b1284137234c6?q=filepath+%5C&rnum=18#cf8b1284137234c6)
-
____________________________________________________________
<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!
-
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
-
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.
-
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?
-
Yes, fixed. Simply removed "Alert(myFile);" and works fine. Thanks Mr ChriZ for all your patience and help. I certainly owe ya a beer!
-
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!