quote:
Originally posted by Mattike
You should use a regular expression for that.
Here's a small function which will return an array containing the information out of a media string.
code:
function parseMedia(Media) {
var mediaExp = /^\\0([a-z]+)\\0([0-1])\\0(.*)\\0(.*)\\0(.*)\\0(.*)\\0(.*)\\0$/i;
if(typeof(Media) == "string" && mediaExp.test(Media)) {
var arr = new Array();
arr['type'] = RegExp.$1;
arr['enabled'] = RegExp.$2;
arr['format'] = RegExp.$3;
arr['title'] = RegExp.$4;
arr['artist'] = RegExp.$5;
arr['album'] = RegExp.$6;
arr['contentId'] = RegExp.$7;
return arr;
} else {
return false;
}
}
An example to use this:
code:
var arrMedia = parseMedia(Messenger.MyCurrentMedia);
if(!arrMedia) {
//Here you can work with the arrMedia array
Debug.Trace("Now Playing: " + arrMedia['artist'] + " - " + arrMedia['title'];
} else {
//The media string was invalid
}
when i use it in the OnEvent_MyMediaChange function it ends up as undefined... i just copied and pasted the code